Various code cleanup.

This commit is contained in:
James Cole
2023-12-22 20:12:38 +01:00
parent 067d160c13
commit 581e5d7330
69 changed files with 361 additions and 317 deletions

View File

@@ -44,8 +44,7 @@ EXIT_CODE=$?
cd $SCRIPT_DIR/..
echo "Exit code is $EXIT_CODE, but we ignore this for the time being."
echo "Exit code is $EXIT_CODE."
# for the time being, exit 0
#exit $EXIT_CODE
exit 0
exit $EXIT_CODE

View File

@@ -37,14 +37,14 @@
<rule ref="rulesets/design.xml/NumberOfChildren">
<properties>
<!-- TODO we want to be at minimum 15. But we start high, and drop the bar slowly. -->
<property name="minimum" value="256"/>
<!-- This is now at 32, which excludes the controllers but should prevent more monoliths. -->
<property name="minimum" value="32"/>
</properties>
</rule>
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
<properties>
<!-- TODO we want to be at maximum 13. But we start high, and drop the bar slowly. -->
<property name="maximum" value="256"/>
<!-- Leaving this at 28 excuses most current code but it can't get worse than that. -->
<property name="maximum" value="28"/>
</properties>
</rule>
@@ -58,14 +58,15 @@
<!-- code size -->
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
<properties>
<!-- TODO we want to be at report level 5. But we start high, and drop the bar slowly. -->
<property name="reportLevel" value="500"/>
<!-- Leave at 20. This means methods will be pretty complex before the system starts complaining. -->
<property name="reportLevel" value="20"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/NPathComplexity">
<properties>
<!-- TODO we want to be at a value of 128. But we start high, and drop the bar slowly. -->
<property name="minimum" value="24062500"/>
<!-- 2000 results in some pretty complex methods, but it's OK. -->
<!-- They should not be much more complex than that though -->
<property name="minimum" value="2000"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">

View File

@@ -40,6 +40,9 @@ use Symfony\Component\HttpFoundation\ParameterBag;
/**
* Class Controller.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.NumberOfChildren)
*/
abstract class Controller extends BaseController
{

View File

@@ -71,7 +71,7 @@ class ShowController extends Controller
* Display a listing of the resource.
*
* @throws FireflyException
* */
*/
public function index(): JsonResponse
{
$pageSize = $this->parameters->get('limit');
@@ -101,7 +101,7 @@ class ShowController extends Controller
* Show a currency.
*
* @throws FireflyException
* */
*/
public function show(TransactionCurrency $currency): JsonResponse
{
/** @var User $user */
@@ -129,7 +129,7 @@ class ShowController extends Controller
* Show a currency.
*
* @throws FireflyException
* */
*/
public function showDefault(): JsonResponse
{
/** @var User $user */

View File

@@ -68,7 +68,7 @@ class StoreController extends Controller
* Store new currency.
*
* @throws FireflyException
* */
*/
public function store(StoreRequest $request): JsonResponse
{
$currency = $this->repository->store($request->getAll());

View File

@@ -69,7 +69,7 @@ class UpdateController extends Controller
* Disable a currency.
*
* @throws FireflyException
* */
*/
public function disable(TransactionCurrency $currency): JsonResponse
{
// must be unused.
@@ -133,7 +133,7 @@ class UpdateController extends Controller
* Enable a currency.
*
* @throws FireflyException
* */
*/
public function enable(TransactionCurrency $currency): JsonResponse
{
$this->repository->enable($currency);
@@ -160,7 +160,7 @@ class UpdateController extends Controller
* Update a currency.
*
* @throws FireflyException
* */
*/
public function update(UpdateRequest $request, TransactionCurrency $currency): JsonResponse
{
$data = $request->getAll();

View File

@@ -45,6 +45,9 @@ use Symfony\Component\HttpFoundation\ParameterBag;
/**
* Class Controller
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.NumberOfChildren)
*/
class Controller extends BaseController
{
@@ -104,6 +107,8 @@ class Controller extends BaseController
/**
* TODO duplicate from V1 controller
* Method to grab all parameters from the URL.
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
private function getParameters(): ParameterBag
{

View File

@@ -45,6 +45,8 @@ class GracefulNotFoundHandler extends ExceptionHandler
* @param Request $request
*
* @throws \Throwable
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function render($request, \Throwable $e): Response
{

View File

@@ -65,11 +65,15 @@ class Handler extends ExceptionHandler
];
/**
* Render an exception into an HTTP response.
* Render an exception into an HTTP response. It's complex but lucky for us, we never use it because
* Firefly III never crashes.
*
* @param Request $request
*
* @throws \Throwable
*
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function render($request, \Throwable $e): Response
{

View File

@@ -68,7 +68,7 @@ class AccountFactory
/**
* @throws FireflyException
* */
*/
public function findOrCreate(string $accountName, string $accountType): Account
{
app('log')->debug(sprintf('findOrCreate("%s", "%s")', $accountName, $accountType));
@@ -100,7 +100,7 @@ class AccountFactory
/**
* @throws FireflyException
* */
*/
public function create(array $data): Account
{
app('log')->debug('Now in AccountFactory::create()');
@@ -171,7 +171,7 @@ class AccountFactory
/**
* @throws FireflyException
* */
*/
private function createAccount(AccountType $type, array $data): Account
{
$this->accountRepository->resetAccountOrder();
@@ -239,7 +239,7 @@ class AccountFactory
/**
* @throws FireflyException
* */
*/
private function cleanMetaDataArray(Account $account, array $data): array
{
$currencyId = array_key_exists('currency_id', $data) ? (int)$data['currency_id'] : 0;

View File

@@ -43,7 +43,7 @@ class BillFactory
/**
* @throws FireflyException
* */
*/
public function create(array $data): ?Bill
{
app('log')->debug(sprintf('Now in %s', __METHOD__), $data);

View File

@@ -52,7 +52,9 @@ class RecurrenceFactory
/**
* @throws FireflyException
* */
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function create(array $data): Recurrence
{
try {

View File

@@ -49,7 +49,7 @@ class TransactionGroupFactory
*
* @throws DuplicateTransactionException
* @throws FireflyException
* */
*/
public function create(array $data): TransactionGroup
{
app('log')->debug('Now in TransactionGroupFactory::create()');

View File

@@ -91,7 +91,7 @@ class TransactionJournalFactory
*
* @throws DuplicateTransactionException
* @throws FireflyException
* */
*/
public function create(array $data): Collection
{
app('log')->debug('Now in TransactionJournalFactory::create()');
@@ -344,7 +344,7 @@ class TransactionJournalFactory
* If this transaction already exists, throw an error.
*
* @throws DuplicateTransactionException
* */
*/
private function errorIfDuplicate(string $hash): void
{
app('log')->debug(sprintf('In errorIfDuplicate(%s)', $hash));
@@ -442,7 +442,7 @@ class TransactionJournalFactory
/**
* @throws FireflyException
* */
*/
private function getCurrencyByAccount(string $type, ?TransactionCurrency $currency, Account $source, Account $destination): TransactionCurrency
{
app('log')->debug('Now in getCurrencyByAccount()');
@@ -455,7 +455,7 @@ class TransactionJournalFactory
/**
* @throws FireflyException
* */
*/
private function getCurrency(?TransactionCurrency $currency, Account $account): TransactionCurrency
{
app('log')->debug('Now in getCurrency()');
@@ -489,7 +489,7 @@ class TransactionJournalFactory
/**
* @throws FireflyException
* */
*/
private function getForeignByAccount(string $type, ?TransactionCurrency $foreignCurrency, Account $destination): ?TransactionCurrency
{
if (TransactionType::TRANSFER === $type) {

View File

@@ -45,7 +45,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
* Generates the report.
*
* @throws FireflyException
* */
*/
public function generate(): string
{
$auditData = [];
@@ -110,7 +110,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
* Get the audit report.
*
* @throws FireflyException
* */
*/
public function getAuditReport(Account $account, Carbon $date): array
{
/** @var AccountRepositoryInterface $accountRepository */

View File

@@ -115,7 +115,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
/**
* @throws FireflyException
* */
*/
private function runWebhook(Webhook $webhook): void
{
app('log')->debug(sprintf('Now in runWebhook(#%d)', $webhook->id));
@@ -128,7 +128,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
/**
* @throws FireflyException
* */
*/
private function generateMessage(Webhook $webhook, Model $model): void
{
$class = get_class($model);

View File

@@ -67,7 +67,9 @@ class EditController extends Controller
}
/**
* Edit account overview.
* Edit account overview. It's complex, but it just has a lot of if/then/else.
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* @return Factory|Redirector|RedirectResponse|View
*/

View File

@@ -146,7 +146,7 @@ class ReconcileController extends Controller
* @return Redirector|RedirectResponse
*
* @throws DuplicateTransactionException
* */
*/
public function submit(ReconciliationStoreRequest $request, Account $account, Carbon $start, Carbon $end)
{
if (!$this->isEditableAccount($account)) {
@@ -188,7 +188,7 @@ class ReconcileController extends Controller
* Creates a reconciliation group.
*
* @throws DuplicateTransactionException
* */
*/
private function createReconciliation(Account $account, Carbon $start, Carbon $end, string $difference): string
{
if (!$this->isEditableAccount($account)) {

View File

@@ -76,8 +76,7 @@ class AccountController extends Controller
* Shows the balances for all the user's expense accounts (on the front page).
*
* This chart is (multi) currency aware.
*
* */
*/
public function expenseAccounts(): JsonResponse
{
/** @var Carbon $start */
@@ -380,7 +379,7 @@ class AccountController extends Controller
* Shows overview of account during a single period.
*
* @throws FireflyException
* */
*/
public function period(Account $account, Carbon $start, Carbon $end): JsonResponse
{
$chartData = [];
@@ -416,7 +415,7 @@ class AccountController extends Controller
* TODO this chart is not multi currency aware.
*
* @throws FireflyException
* */
*/
public function report(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
return response()->json($this->accountBalanceChart($accounts, $start, $end));
@@ -426,8 +425,7 @@ class AccountController extends Controller
* Shows the balances for all the user's revenue accounts.
*
* This chart is multi-currency aware.
*
* */
*/
public function revenueAccounts(): JsonResponse
{
/** @var Carbon $start */
@@ -517,7 +515,7 @@ class AccountController extends Controller
/**
* @throws FireflyException
* */
*/
private function periodByCurrency(Carbon $start, Carbon $end, Account $account, TransactionCurrency $currency): array
{
app('log')->debug(sprintf('Now in periodByCurrency("%s", "%s", %s, "%s")', $start->format('Y-m-d'), $end->format('Y-m-d'), $account->id, $currency->code));

View File

@@ -32,6 +32,9 @@ use Illuminate\Routing\Controller as BaseController;
/**
* Class Controller.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.NumberOfChildren)
*/
abstract class Controller extends BaseController
{

View File

@@ -65,7 +65,7 @@ class ReconcileController extends Controller
* Overview of reconciliation.
*
* @throws FireflyException
* */
*/
public function overview(Request $request, Account $account = null, Carbon $start = null, Carbon $end = null): JsonResponse
{
$startBalance = $request->get('startBalance');
@@ -165,7 +165,7 @@ class ReconcileController extends Controller
* @return JsonResponse
*
* @throws FireflyException
* */
*/
public function transactions(Account $account, Carbon $start = null, Carbon $end = null)
{
if (null === $start || null === $end) {

View File

@@ -59,6 +59,8 @@ class RecurrenceController extends Controller
/**
* Shows all events for a repetition. Used in calendar.
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* @throws FireflyException
*/
public function events(Request $request): JsonResponse

View File

@@ -74,7 +74,7 @@ class IndexController extends Controller
* @return Factory|View
*
* @throws FireflyException
* */
*/
public function index()
{
$this->cleanupObjectGroups();

View File

@@ -66,7 +66,7 @@ class ShowController extends Controller
* @return Factory|View
*
* @throws FireflyException
* */
*/
public function show(PiggyBank $piggyBank)
{
/** @var Carbon $end */

View File

@@ -150,6 +150,7 @@ class PreferencesController extends Controller
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function postIndex(Request $request)
{

View File

@@ -66,7 +66,7 @@ class BudgetController extends Controller
* @return Factory|View
*
* @throws FireflyException
* */
*/
public function accountPerBudget(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
{
/** @var BudgetReportGenerator $generator */
@@ -257,7 +257,7 @@ class BudgetController extends Controller
* @return string
*
* @throws FireflyException
* */
*/
public function general(Collection $accounts, Carbon $start, Carbon $end)
{
/** @var BudgetReportGenerator $generator */

View File

@@ -85,6 +85,8 @@ use Laravel\Passport\Events\AccessTokenCreated;
/**
* Class EventServiceProvider.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class EventServiceProvider extends ServiceProvider
{

View File

@@ -75,6 +75,8 @@ use Illuminate\Support\ServiceProvider;
/**
* Class FireflyServiceProvider.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class FireflyServiceProvider extends ServiceProvider
{

View File

@@ -221,7 +221,7 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @throws FireflyException
* */
*/
public function getCashAccount(): Account
{
/** @var AccountType $type */
@@ -342,7 +342,7 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @throws FireflyException
* */
*/
public function getReconciliation(Account $account): ?Account
{
if (AccountType::ASSET !== $account->accountType->type) {
@@ -617,7 +617,7 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @throws FireflyException
* */
*/
public function store(array $data): Account
{
/** @var AccountFactory $factory */
@@ -629,7 +629,7 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @throws FireflyException
* */
*/
public function update(Account $account, array $data): Account
{
/** @var AccountUpdateService $service */

View File

@@ -42,7 +42,7 @@ class AccountTasker implements AccountTaskerInterface
/**
* @throws FireflyException
* */
*/
public function getAccountReport(Collection $accounts, Carbon $start, Carbon $end): array
{
$yesterday = clone $start;
@@ -109,7 +109,7 @@ class AccountTasker implements AccountTaskerInterface
/**
* @throws FireflyException
* */
*/
public function getExpenseReport(Carbon $start, Carbon $end, Collection $accounts): array
{
// get all expenses for the given accounts in the given period!
@@ -140,7 +140,7 @@ class AccountTasker implements AccountTaskerInterface
/**
* @throws FireflyException
* */
*/
public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): array
{
// get all incomes for the given accounts in the given period!
@@ -175,7 +175,7 @@ class AccountTasker implements AccountTaskerInterface
/**
* @throws FireflyException
* */
*/
private function groupExpenseByDestination(array $array): array
{
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
@@ -235,7 +235,7 @@ class AccountTasker implements AccountTaskerInterface
/**
* @throws FireflyException
* */
*/
private function groupIncomeBySource(array $array): array
{
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);

View File

@@ -218,6 +218,7 @@ class OperationsRepository implements OperationsRepositoryInterface
/**
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
private function getTransactionsForSum(
string $type,

View File

@@ -421,8 +421,7 @@ class BillRepository implements BillRepositoryInterface
/**
* Given the date in $date, this method will return a moment in the future where the bill is expected to be paid.
*
* */
*/
public function nextExpectedMatch(Bill $bill, Carbon $date): Carbon
{
$cache = new CacheProperties();
@@ -463,7 +462,7 @@ class BillRepository implements BillRepositoryInterface
/**
* @throws FireflyException
* */
*/
public function store(array $data): Bill
{
/** @var BillFactory $factory */
@@ -643,7 +642,7 @@ class BillRepository implements BillRepositoryInterface
/**
* @throws FireflyException
* */
*/
public function update(Bill $bill, array $data): Bill
{
/** @var BillUpdateService $service */

View File

@@ -261,7 +261,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
/**
* @throws FireflyException
* */
*/
public function store(array $data): BudgetLimit
{
// if no currency has been provided, use the user's default currency:
@@ -316,7 +316,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
/**
* @throws FireflyException
* */
*/
public function update(BudgetLimit $budgetLimit, array $data): BudgetLimit
{
$budgetLimit->amount = array_key_exists('amount', $data) ? $data['amount'] : $budgetLimit->amount;

View File

@@ -233,7 +233,7 @@ class BudgetRepository implements BudgetRepositoryInterface
/**
* @throws FireflyException
* */
*/
public function update(Budget $budget, array $data): Budget
{
app('log')->debug('Now in update()');
@@ -564,7 +564,9 @@ class BudgetRepository implements BudgetRepositoryInterface
/**
* @throws FireflyException
* */
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function store(array $data): Budget
{
$order = $this->getMaxOrder();
@@ -750,7 +752,7 @@ class BudgetRepository implements BudgetRepositoryInterface
/**
* @throws FireflyException
* */
*/
private function updateAutoBudget(Budget $budget, array $data): void
{
// update or create auto-budget:

View File

@@ -135,7 +135,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
* Used for connecting to a piggy bank.
*
* @throws FireflyException
* */
*/
public function getExactAmount(PiggyBank $piggyBank, PiggyBankRepetition $repetition, TransactionJournal $journal): string
{
app('log')->debug(sprintf('Now in getExactAmount(%d, %d, %d)', $piggyBank->id, $repetition->id, $journal->id));
@@ -318,8 +318,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
/**
* Get for piggy account what is left to put in piggies.
*
* */
*/
public function leftOnAccount(PiggyBank $piggyBank, Carbon $date): string
{
$balance = app('steam')->balanceIgnoreVirtual($piggyBank->account, $date);

View File

@@ -258,8 +258,7 @@ class RecurringRepository implements RecurringRepositoryInterface
/**
* Get the tags from the recurring transaction.
*
* */
*/
public function getTags(RecurrenceTransaction $transaction): array
{
$tags = [];
@@ -479,7 +478,7 @@ class RecurringRepository implements RecurringRepositoryInterface
/**
* @throws FireflyException
* */
*/
public function store(array $data): Recurrence
{
/** @var RecurrenceFactory $factory */

View File

@@ -255,7 +255,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
* Return all piggy bank events for all journals in the group.
*
* @throws FireflyException
* */
*/
public function getPiggyEvents(TransactionGroup $group): array
{
$return = [];
@@ -318,7 +318,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
/**
* @throws DuplicateTransactionException
* @throws FireflyException
* */
*/
public function store(array $data): TransactionGroup
{
/** @var TransactionGroupFactory $factory */

View File

@@ -157,6 +157,8 @@ class UserGroupRepository implements UserGroupRepositoryInterface
}
/**
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* @throws FireflyException
*/
public function updateMembership(UserGroup $userGroup, array $data): UserGroup

View File

@@ -217,7 +217,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
* Find by object, ID or code. Returns user default or system default.
*
* @throws FireflyException
* */
*/
public function findCurrency(?int $currencyId, ?string $currencyCode): TransactionCurrency
{
$result = $this->findCurrencyNull($currencyId, $currencyCode);

View File

@@ -88,6 +88,8 @@ trait AccountServiceTrait
/**
* Update metadata for account. Depends on type which fields are valid.
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* TODO this method treats expense accounts and liabilities the same way (tries to save interest)
*/
public function updateMetaData(Account $account, array $data): void
@@ -336,7 +338,7 @@ trait AccountServiceTrait
/**
* @throws FireflyException
* */
*/
protected function getCurrency(int $currencyId, string $currencyCode): TransactionCurrency
{
// find currency, or use default currency instead.
@@ -360,7 +362,7 @@ trait AccountServiceTrait
* Create the opposing "credit liability" transaction for credit liabilities.
*
* @throws FireflyException
* */
*/
protected function updateCreditTransaction(Account $account, string $direction, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
@@ -416,7 +418,7 @@ trait AccountServiceTrait
/**
* @throws FireflyException
* */
*/
protected function createCreditTransaction(Account $account, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
{
app('log')->debug('Now going to create an createCreditTransaction.');
@@ -510,7 +512,7 @@ trait AccountServiceTrait
* Since opening balance and date can still be empty strings, it may fail.
*
* @throws FireflyException
* */
*/
protected function updateOBGroupV2(Account $account, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
@@ -566,7 +568,7 @@ trait AccountServiceTrait
/**
* @throws FireflyException
* */
*/
protected function createOBGroupV2(Account $account, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
{
app('log')->debug('Now going to create an OB group.');

View File

@@ -243,7 +243,11 @@ class CreditRecalculateService
}
/**
* A complex and long method, but rarely used luckily.
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function processTransaction(Account $account, string $direction, Transaction $transaction, string $leftOfDebt): string
{

View File

@@ -87,7 +87,9 @@ trait RecurringTransactionTrait
* Store transactions of a recurring transactions. It's complex but readable.
*
* @throws FireflyException
* */
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function createTransactions(Recurrence $recurrence, array $transactions): void
{
app('log')->debug('Now in createTransactions()');

View File

@@ -63,7 +63,7 @@ class AccountUpdateService
* Update account data.
*
* @throws FireflyException
* */
*/
public function update(Account $account, array $data): Account
{
app('log')->debug(sprintf('Now in %s', __METHOD__));

View File

@@ -46,7 +46,7 @@ class BillUpdateService
/**
* @throws FireflyException
* */
*/
public function update(Bill $bill, array $data): Bill
{
$this->user = $bill->user;
@@ -129,6 +129,9 @@ class BillUpdateService
return $bill;
}
/**
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
private function updateBillProperties(Bill $bill, array $data): Bill
{
if (array_key_exists('name', $data) && '' !== (string) $data['name']) {

View File

@@ -41,7 +41,7 @@ class GroupUpdateService
*
* @throws DuplicateTransactionException
* @throws FireflyException
* */
*/
public function update(TransactionGroup $transactionGroup, array $data): TransactionGroup
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
@@ -149,7 +149,7 @@ class GroupUpdateService
/**
* @throws DuplicateTransactionException
* @throws FireflyException
* */
*/
private function updateTransactions(TransactionGroup $transactionGroup, array $transactions): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
@@ -206,7 +206,7 @@ class GroupUpdateService
/**
* @throws DuplicateTransactionException
* @throws FireflyException
* */
*/
private function createTransactionJournal(TransactionGroup $transactionGroup, array $data): ?TransactionJournal
{
$submission = [

View File

@@ -192,7 +192,7 @@ class RecurrenceUpdateService
* TODO this method is very complex.
*
* @throws FireflyException
* */
*/
private function updateTransactions(Recurrence $recurrence, array $transactions): void
{
app('log')->debug('Now in updateTransactions()');
@@ -244,17 +244,22 @@ class RecurrenceUpdateService
$this->createTransactions($recurrence, $transactions);
}
/**
* It's a complex method but nothing surprising.
*
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function updateCombination(Recurrence $recurrence, array $combination): void
{
$original = $combination['original'];
$submitted = $combination['submitted'];
$currencyFactory = app(TransactionCurrencyFactory::class);
/** @var RecurrenceTransaction $transaction */
$transaction = $recurrence->recurrenceTransactions()->find($original['id']);
app('log')->debug(sprintf('Now in updateCombination(#%d)', $original['id']));
$currencyFactory = app(TransactionCurrencyFactory::class);
// loop all and try to match them:
$currency = null;
$foreignCurrency = null;

View File

@@ -40,7 +40,7 @@ trait ChartGeneration
* Shows an overview of the account balances for a set of accounts.
*
* @throws FireflyException
* */
*/
protected function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array // chart helper method.
{
// chart properties for cache:

View File

@@ -70,6 +70,8 @@ class ParseDateString
/**
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function parseDate(string $date): Carbon
{

View File

@@ -134,7 +134,7 @@ class BudgetReportGenerator
/**
* @throws FireflyException
* */
*/
public function setUser(User $user): void
{
$this->repository->setUser($user);

View File

@@ -31,59 +31,24 @@ trait GetRecurrenceData
protected function getSingleTransactionData(array $transaction): array
{
$return = [];
$stringKeys = ['id'];
$intKeys = ['currency_id', 'foreign_currency_id', 'source_id', 'destination_id', 'bill_id', 'piggy_bank_id', 'bill_id', 'budget_id', 'category_id'];
$keys = ['amount', 'currency_code', 'foreign_amount', 'foreign_currency_code', 'description', 'tags'];
if (array_key_exists('id', $transaction)) {
$return['id'] = (string)$transaction['id'];
foreach ($stringKeys as $key) {
if (array_key_exists($key, $transaction)) {
$return[$key] = (string) $transaction[$key];
}
// amount + currency
if (array_key_exists('amount', $transaction)) {
$return['amount'] = $transaction['amount'];
}
if (array_key_exists('currency_id', $transaction)) {
$return['currency_id'] = (int)$transaction['currency_id'];
foreach ($intKeys as $key) {
if (array_key_exists($key, $transaction)) {
$return[$key] = (int) $transaction[$key];
}
if (array_key_exists('currency_code', $transaction)) {
$return['currency_code'] = $transaction['currency_code'];
}
// foreign amount + currency
if (array_key_exists('foreign_amount', $transaction)) {
$return['foreign_amount'] = $transaction['foreign_amount'];
foreach ($keys as $key) {
if (array_key_exists($key, $transaction)) {
$return[$key] = $transaction[$key];
}
if (array_key_exists('foreign_currency_id', $transaction)) {
$return['foreign_currency_id'] = (int)$transaction['foreign_currency_id'];
}
if (array_key_exists('foreign_currency_code', $transaction)) {
$return['foreign_currency_code'] = $transaction['foreign_currency_code'];
}
// source + dest
if (array_key_exists('source_id', $transaction)) {
$return['source_id'] = (int)$transaction['source_id'];
}
if (array_key_exists('destination_id', $transaction)) {
$return['destination_id'] = (int)$transaction['destination_id'];
}
// description
if (array_key_exists('description', $transaction)) {
$return['description'] = $transaction['description'];
}
if (array_key_exists('piggy_bank_id', $transaction)) {
$return['piggy_bank_id'] = (int)$transaction['piggy_bank_id'];
}
if (array_key_exists('bill_id', $transaction)) {
$return['bill_id'] = (int)$transaction['bill_id'];
}
if (array_key_exists('tags', $transaction)) {
$return['tags'] = $transaction['tags'];
}
if (array_key_exists('budget_id', $transaction)) {
$return['budget_id'] = (int)$transaction['budget_id'];
}
if (array_key_exists('category_id', $transaction)) {
$return['category_id'] = (int)$transaction['category_id'];
}
return $return;

View File

@@ -59,6 +59,8 @@ use Illuminate\Support\Collection;
/**
* Class OperatorQuerySearch
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class OperatorQuerySearch implements SearchInterface
{
@@ -242,6 +244,8 @@ class OperatorQuerySearch implements SearchInterface
/**
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function handleSearchNode(Node $searchNode): void
{
@@ -325,6 +329,7 @@ class OperatorQuerySearch implements SearchInterface
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function updateCollector(string $operator, string $value, bool $prohibited): bool
{
@@ -1974,6 +1979,7 @@ class OperatorQuerySearch implements SearchInterface
* stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
private function searchAccountNr(string $value, SearchDirection $searchDirection, StringPosition $stringPosition, bool $prohibited = false): void
{

View File

@@ -87,7 +87,7 @@ class Steam
* [yyyy-mm-dd] => 123,2
*
* @throws FireflyException
* */
*/
public function balanceInRange(Account $account, Carbon $start, Carbon $end, ?TransactionCurrency $currency = null): array
{
$cache = new CacheProperties();

View File

@@ -29,7 +29,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Search\OperatorQuerySearch;
use League\CommonMark\GithubFlavoredMarkdownConverter;
use Route;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
@@ -111,6 +110,8 @@ class General extends AbstractExtension
/**
* Show icon with attachment.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function mimeIcon(): TwigFilter
{

View File

@@ -121,7 +121,7 @@ class ConvertToDeposit implements ActionInterface
* Is converted to a deposit from C to A.
*
* @throws FireflyException
* */
*/
private function convertWithdrawalArray(TransactionJournal $journal): bool
{
$user = $journal->user;
@@ -210,7 +210,7 @@ class ConvertToDeposit implements ActionInterface
* The source account is replaced.
*
* @throws FireflyException
* */
*/
private function convertTransferArray(TransactionJournal $journal): bool
{
$user = $journal->user;

View File

@@ -51,6 +51,7 @@ class ConvertToTransfer implements ActionInterface
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function actOnArray(array $journal): bool
{

View File

@@ -116,7 +116,7 @@ class ConvertToWithdrawal implements ActionInterface
/**
* @throws FireflyException
* */
*/
private function convertDepositArray(TransactionJournal $journal): bool
{
$user = $journal->user;
@@ -202,7 +202,7 @@ class ConvertToWithdrawal implements ActionInterface
* Output is a withdrawal from A to C.
*
* @throws FireflyException
* */
*/
private function convertTransferArray(TransactionJournal $journal): bool
{
// find or create expense account.

View File

@@ -49,7 +49,7 @@ class AccountTransformer extends AbstractTransformer
* Transform the account.
*
* @throws FireflyException
* */
*/
public function transform(Account $account): array
{
$this->repository->setUser($account->user);
@@ -156,7 +156,7 @@ class AccountTransformer extends AbstractTransformer
/**
* @throws FireflyException
* */
*/
private function getCurrency(Account $account): array
{
$currency = $this->repository->getAccountCurrency($account);

View File

@@ -53,6 +53,7 @@ class BillTransformer extends AbstractTransformer
* Transform the bill.
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function transform(Bill $bill): array
{

View File

@@ -49,7 +49,7 @@ class PiggyBankEventTransformer extends AbstractTransformer
* Convert piggy bank event.
*
* @throws FireflyException
* */
*/
public function transform(PiggyBankEvent $event): array
{
// get account linked to piggy bank

View File

@@ -50,7 +50,7 @@ class PiggyBankTransformer extends AbstractTransformer
* Transform the piggy bank.
*
* @throws FireflyException
* */
*/
public function transform(PiggyBank $piggyBank): array
{
$account = $piggyBank->account;

View File

@@ -139,7 +139,7 @@ class PiggyBankTransformer extends AbstractTransformer
* Transform the piggy bank.
*
* @throws FireflyException
* */
*/
public function transform(PiggyBank $piggyBank): array
{
// $account = $piggyBank->account;

View File

@@ -76,6 +76,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class User.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
* @property int|string $id
* @property string $email
* @property bool $isAdmin

View File

@@ -78,6 +78,12 @@ trait DepositValidation
abstract protected function findExistingAccount(array $validTypes, array $data): ?Account;
/**
* Pretty complex unfortunately.
*
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function validateDepositSource(array $array): bool
{
$accountId = array_key_exists('id', $array) ? $array['id'] : null;

View File

@@ -247,7 +247,11 @@ class AccountValidator
}
/**
* It's a long and fairly complex method, but I don't mind.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function findExistingAccount(array $validTypes, array $data, bool $inverse = false): ?Account
{

View File

@@ -30,6 +30,9 @@ use Illuminate\Validation\Validator;
*/
trait ValidatesAutoBudgetRequest
{
/**
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function validateAutoBudgetAmount(Validator $validator): void
{
$data = $validator->getData();

View File

@@ -299,6 +299,9 @@ trait RecurrenceValidation
}
}
/**
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function validateTransactionId(Recurrence $recurrence, Validator $validator): void
{
app('log')->debug('Now in validateTransactionId');

View File

@@ -217,6 +217,9 @@ trait TransactionValidation
return $transactions;
}
/**
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function validateSingleAccount(Validator $validator, int $index, string $transactionType, array $transaction): void
{
app('log')->debug(sprintf('Now in validateSingleAccount(%d)', $index));
@@ -395,6 +398,7 @@ trait TransactionValidation
* TODO describe this method.
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
private function sanityCheckForeignCurrency(
Validator $validator,

View File

@@ -527,6 +527,7 @@ class CreateMainTables extends Migration
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
private function createTransactionTables(): void
{

View File

@@ -125,6 +125,7 @@ class ChangesForV550 extends Migration
*
* @SuppressWarnings(PHPMD.ShortMethodName)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function up(): void
{