From b9feb0aa71549e2de38a4eb5c618747774239074 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 29 Nov 2023 06:30:35 +0100 Subject: [PATCH] Fix various phpstan things --- .../Budget/BudgetLimitController.php | 3 +- .../Controllers/Budget/IndexController.php | 13 +++--- app/Http/Controllers/DebugController.php | 4 +- app/Http/Controllers/JavascriptController.php | 10 ++--- .../Controllers/PiggyBank/IndexController.php | 4 +- .../Transaction/ShowController.php | 5 +-- .../Controllers/Webhooks/IndexController.php | 6 +-- app/Http/Middleware/Authenticate.php | 1 + .../Budget/OperationsRepository.php | 17 -------- .../Http/Api/ValidatesUserGroupTrait.php | 2 +- app/Support/Http/Controllers/AugumentData.php | 14 +++++- .../Http/Controllers/GetConfigurationData.php | 4 +- .../Http/Controllers/ModelInformation.php | 1 + .../Http/Controllers/RenderPartialViews.php | 8 +++- .../Repositories/UserGroup/UserGroupTrait.php | 4 ++ app/Support/Request/ChecksLogin.php | 2 +- app/Support/Request/ConvertsDataTypes.php | 6 +-- app/Validation/FireflyValidator.php | 43 ++++++++++++------- app/Validation/TransactionValidation.php | 8 ++-- 19 files changed, 77 insertions(+), 78 deletions(-) diff --git a/app/Http/Controllers/Budget/BudgetLimitController.php b/app/Http/Controllers/Budget/BudgetLimitController.php index 18696c7156..3a7605bd78 100644 --- a/app/Http/Controllers/Budget/BudgetLimitController.php +++ b/app/Http/Controllers/Budget/BudgetLimitController.php @@ -106,12 +106,11 @@ class BudgetLimitController extends Controller } /** - * @param Request $request * @param BudgetLimit $budgetLimit * * @return RedirectResponse|Redirector */ - public function delete(Request $request, BudgetLimit $budgetLimit) + public function delete(BudgetLimit $budgetLimit) { $this->blRepository->destroyBudgetLimit($budgetLimit); session()->flash('success', trans('firefly.deleted_bl')); diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.php index 23b54d6da6..534fb9b8d5 100644 --- a/app/Http/Controllers/Budget/IndexController.php +++ b/app/Http/Controllers/Budget/IndexController.php @@ -87,8 +87,6 @@ class IndexController extends Controller /** * Show all budgets. * - * @param Request $request - * * @param Carbon|null $start * @param Carbon|null $end * @@ -98,7 +96,7 @@ class IndexController extends Controller * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function index(Request $request, Carbon $start = null, Carbon $end = null) + public function index(Carbon $start = null, Carbon $end = null) { $this->abRepository->cleanup(); app('log')->debug(sprintf('Start of IndexController::index("%s", "%s")', $start?->format('Y-m-d'), $end?->format('Y-m-d'))); @@ -137,7 +135,7 @@ class IndexController extends Controller // get budgeted for default currency: if (0 === count($availableBudgets)) { - $budgeted = $this->blRepository->budgeted($start, $end, $defaultCurrency, ); + $budgeted = $this->blRepository->budgeted($start, $end, $defaultCurrency,); $spentArr = $this->opsRepository->sumExpenses($start, $end, null, null, $defaultCurrency); $spent = $spentArr[$defaultCurrency->id]['sum'] ?? '0'; unset($spentArr); @@ -196,7 +194,7 @@ class IndexController extends Controller $array['spent'] = $spentArr[$entry->transaction_currency_id]['sum'] ?? '0'; // budgeted in period: - $budgeted = $this->blRepository->budgeted($entry->start_date, $entry->end_date, $entry->transactionCurrency, ); + $budgeted = $this->blRepository->budgeted($entry->start_date, $entry->end_date, $entry->transactionCurrency,); $array['budgeted'] = $budgeted; $availableBudgets[] = $array; unset($spentArr); @@ -320,10 +318,9 @@ class IndexController extends Controller } // final calculation for 'left': /** - * @var int $currencyId - * @var array $info + * @var int $currencyId */ - foreach ($sums['budgeted'] as $currencyId => $info) { + foreach (array_keys($sums['budgeted']) as $currencyId) { $spent = $sums['spent'][$currencyId]['amount'] ?? '0'; $budgeted = $sums['budgeted'][$currencyId]['amount'] ?? '0'; $sums['left'][$currencyId]['amount'] = bcadd($spent, $budgeted); diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php index 126b19a845..f2b9934c14 100644 --- a/app/Http/Controllers/DebugController.php +++ b/app/Http/Controllers/DebugController.php @@ -115,12 +115,10 @@ class DebugController extends Controller /** * Show debug info. * - * @param Request $request - * * @return Factory|View * @throws FireflyException */ - public function index(Request $request) + public function index() { $table = $this->generateTable(); $table = str_replace(["\n", "\t", ' '], '', $table); diff --git a/app/Http/Controllers/JavascriptController.php b/app/Http/Controllers/JavascriptController.php index 614f491830..b10f43dd89 100644 --- a/app/Http/Controllers/JavascriptController.php +++ b/app/Http/Controllers/JavascriptController.php @@ -48,13 +48,12 @@ class JavascriptController extends Controller * Show info about accounts. * * @param AccountRepositoryInterface $repository - * @param CurrencyRepositoryInterface $currencyRepository * * @return Response * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response + public function accounts(AccountRepositoryInterface $repository): Response { $accounts = $repository->getAccountsByType( [AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD] @@ -104,7 +103,6 @@ class JavascriptController extends Controller * * @param Request $request * @param AccountRepositoryInterface $repository - * @param CurrencyRepositoryInterface $currencyRepository * * @return Response * @throws FireflyException @@ -112,7 +110,7 @@ class JavascriptController extends Controller * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function variables(Request $request, AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response + public function variables(Request $request, AccountRepositoryInterface $repository): Response { $account = $repository->find((int)$request->get('account')); $currency = app('amount')->getDefaultCurrency(); @@ -147,11 +145,9 @@ class JavascriptController extends Controller /** * Bit of a hack but OK. * - * @param Request $request - * * @return Response */ - public function variablesV2(Request $request): Response + public function variablesV2(): Response { /** @var Carbon $start */ $start = clone session('start', today(config('app.timezone'))->startOfMonth()); diff --git a/app/Http/Controllers/PiggyBank/IndexController.php b/app/Http/Controllers/PiggyBank/IndexController.php index fb0412e1cd..732bf18cd3 100644 --- a/app/Http/Controllers/PiggyBank/IndexController.php +++ b/app/Http/Controllers/PiggyBank/IndexController.php @@ -74,13 +74,11 @@ class IndexController extends Controller * * TODO very complicated function. * - * @param Request $request - * * @return Factory|View * @throws FireflyException * @throws JsonException */ - public function index(Request $request) + public function index() { $this->cleanupObjectGroups(); $this->piggyRepos->resetOrder(); diff --git a/app/Http/Controllers/Transaction/ShowController.php b/app/Http/Controllers/Transaction/ShowController.php index cdc5615e79..83b205fe1b 100644 --- a/app/Http/Controllers/Transaction/ShowController.php +++ b/app/Http/Controllers/Transaction/ShowController.php @@ -76,13 +76,12 @@ class ShowController extends Controller } /** - * @param Request $request * @param TransactionGroup $transactionGroup * * @return Factory|View * @throws FireflyException */ - public function show(Request $request, TransactionGroup $transactionGroup) + public function show( TransactionGroup $transactionGroup) { /** @var TransactionJournal|null $first */ $first = $transactionGroup->transactionJournals()->first(['transaction_journals.*']); @@ -105,7 +104,7 @@ class ShowController extends Controller $amounts = $this->getAmounts($groupArray); $accounts = $this->getAccounts($groupArray); - foreach ($groupArray['transactions'] as $index => $transaction) { + foreach (array_keys($groupArray['transactions']) as $index) { $groupArray['transactions'][$index]['tags'] = $this->repository->getTagObjects( $groupArray['transactions'][$index]['transaction_journal_id'] ); diff --git a/app/Http/Controllers/Webhooks/IndexController.php b/app/Http/Controllers/Webhooks/IndexController.php index eafc423f32..a5a868fd31 100644 --- a/app/Http/Controllers/Webhooks/IndexController.php +++ b/app/Http/Controllers/Webhooks/IndexController.php @@ -53,13 +53,9 @@ class IndexController extends Controller } /** - * Show debug info. - * - * @param Request $request - * * @return Factory|View */ - public function index(Request $request) + public function index() { return view('webhooks.index'); } diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 2d867f52b8..388a566dda 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -83,6 +83,7 @@ class Authenticate * @return mixed * @throws FireflyException * @throws AuthenticationException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function authenticate($request, array $guards) { diff --git a/app/Repositories/Budget/OperationsRepository.php b/app/Repositories/Budget/OperationsRepository.php index 22ddc55675..3ee62ff3c0 100644 --- a/app/Repositories/Budget/OperationsRepository.php +++ b/app/Repositories/Budget/OperationsRepository.php @@ -324,21 +324,4 @@ class OperationsRepository implements OperationsRepositoryInterface return $array; } - /** - * For now, simply refer to whichever repository holds this function. - * TODO perhaps better in the future. - * - * @param Budget $budget - * @param Carbon|null $start - * @param Carbon|null $end - * - * @return Collection - */ - private function getBudgetLimits(Budget $budget, Carbon $start = null, Carbon $end = null): Collection - { - /** @var BudgetLimitRepositoryInterface $blRepository */ - $blRepository = app(BudgetLimitRepositoryInterface::class); - - return $blRepository->getBudgetLimits($budget, $start, $end); - } } diff --git a/app/Support/Http/Api/ValidatesUserGroupTrait.php b/app/Support/Http/Api/ValidatesUserGroupTrait.php index abc8666155..69041f154e 100644 --- a/app/Support/Http/Api/ValidatesUserGroupTrait.php +++ b/app/Support/Http/Api/ValidatesUserGroupTrait.php @@ -52,7 +52,7 @@ trait ValidatesUserGroupTrait $user = auth()->user(); if (!$request->has('user_group_id')) { $group = $user->userGroup; - app('log')->debug(sprintf('validateUserGroup: no user group submitted, return default group #%d.', $group->id)); + app('log')->debug(sprintf('validateUserGroup: no user group submitted, return default group #%d.', $group?->id)); return $group; } $groupId = (int)$request->get('user_group_id'); diff --git a/app/Support/Http/Controllers/AugumentData.php b/app/Support/Http/Controllers/AugumentData.php index 014a802749..4821aa45e8 100644 --- a/app/Support/Http/Controllers/AugumentData.php +++ b/app/Support/Http/Controllers/AugumentData.php @@ -36,6 +36,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Support\CacheProperties; +use FireflyIII\Support\Facades\Amount; use Illuminate\Support\Collection; /** @@ -216,9 +217,20 @@ trait AugumentData /** @var BudgetLimit $entry */ foreach ($set as $entry) { $currency = $entry->transactionCurrency; + + if(null === $currency) { + $currency = app('amount')->getDefaultCurrency(); + } + // clone because these objects change each other. $currentStart = clone $entry->start_date; - $currentEnd = clone $entry->end_date; + $currentEnd = null === $entry->end_date ? null : clone $entry->end_date; + + if(null === $currentEnd) { + $currentEnd = clone $currentStart; + $currentEnd->addMonth(); + } + $expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $currency); $spent = $expenses[$currency->id]['sum'] ?? '0'; $entry->spent = $spent; diff --git a/app/Support/Http/Controllers/GetConfigurationData.php b/app/Support/Http/Controllers/GetConfigurationData.php index bb286efeaa..eebadefb10 100644 --- a/app/Support/Http/Controllers/GetConfigurationData.php +++ b/app/Support/Http/Controllers/GetConfigurationData.php @@ -220,9 +220,9 @@ trait GetConfigurationData protected function verifyRecurringCronJob(): void { $config = app('fireflyconfig')->get('last_rt_job', 0); - $lastTime = (int)$config->data; + $lastTime = (int)$config?->data; $now = time(); - app('log')->debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config->data, $now)); + app('log')->debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config?->data, $now)); if (0 === $lastTime) { request()->session()->flash('info', trans('firefly.recurring_never_cron')); diff --git a/app/Support/Http/Controllers/ModelInformation.php b/app/Support/Http/Controllers/ModelInformation.php index 856a579320..7fce876f08 100644 --- a/app/Support/Http/Controllers/ModelInformation.php +++ b/app/Support/Http/Controllers/ModelInformation.php @@ -79,6 +79,7 @@ trait ModelInformation /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); // types of liability: + /** @var AccountType $debt */ $debt = $repository->getAccountTypeByType(AccountType::DEBT); $loan = $repository->getAccountTypeByType(AccountType::LOAN); $mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE); diff --git a/app/Support/Http/Controllers/RenderPartialViews.php b/app/Support/Http/Controllers/RenderPartialViews.php index 867393cdbb..13e3518d20 100644 --- a/app/Support/Http/Controllers/RenderPartialViews.php +++ b/app/Support/Http/Controllers/RenderPartialViews.php @@ -64,6 +64,10 @@ trait RenderPartialViews $accountRepos = app(AccountRepositoryInterface::class); $account = $accountRepos->find((int)$attributes['accountId']); + if(null === $budget || null === $account) { + throw new FireflyException('Could not render popup.report.balance-amount because budget or account is null.'); + } + $journals = $popupHelper->balanceForBudget($budget, $account, $attributes); try { @@ -330,7 +334,7 @@ trait RenderPartialViews if ('user_action' !== $entry->trigger_type) { $count = ($index + 1); try { - $rootOperator = OperatorQuerySearch::getRootOperator($entry->trigger_type); + $rootOperator = OperatorQuerySearch::getRootOperator((string) $entry->trigger_type); if (str_starts_with($rootOperator, '-')) { $rootOperator = substr($rootOperator, 1); } @@ -340,7 +344,7 @@ trait RenderPartialViews 'oldTrigger' => $rootOperator, 'oldValue' => $entry->trigger_value, 'oldChecked' => $entry->stop_processing, - 'oldProhibited' => str_starts_with($entry->trigger_type, '-'), + 'oldProhibited' => str_starts_with((string) $entry->trigger_type, '-'), 'count' => $count, 'triggers' => $triggers, ] diff --git a/app/Support/Repositories/UserGroup/UserGroupTrait.php b/app/Support/Repositories/UserGroup/UserGroupTrait.php index 9db484dc58..9c659a6a3e 100644 --- a/app/Support/Repositories/UserGroup/UserGroupTrait.php +++ b/app/Support/Repositories/UserGroup/UserGroupTrait.php @@ -63,11 +63,15 @@ trait UserGroupTrait * @param Authenticatable|User|null $user * * @return void + * @throws FireflyException */ public function setUser(Authenticatable | User | null $user): void { if ($user instanceof User) { $this->user = $user; + if(null === $user->userGroup) { + throw new FireflyException(sprintf('User #%d has no user group.', $user->id)); + } $this->userGroup = $user->userGroup; } } diff --git a/app/Support/Request/ChecksLogin.php b/app/Support/Request/ChecksLogin.php index 90ac3207ee..7c215e77a6 100644 --- a/app/Support/Request/ChecksLogin.php +++ b/app/Support/Request/ChecksLogin.php @@ -79,7 +79,7 @@ trait ChecksLogin $user = auth()->user(); app('log')->debug('Now in getUserGroup()'); /** @var UserGroup|null $userGroup */ - $userGroup = $this->route()->parameter('userGroup'); + $userGroup = $this->route()?->parameter('userGroup'); if (null === $userGroup) { app('log')->debug('Request class has no userGroup parameter, but perhaps there is a parameter.'); $userGroupId = (int)$this->get('user_group_id'); diff --git a/app/Support/Request/ConvertsDataTypes.php b/app/Support/Request/ConvertsDataTypes.php index 00102adccc..ca2270189f 100644 --- a/app/Support/Request/ConvertsDataTypes.php +++ b/app/Support/Request/ConvertsDataTypes.php @@ -70,7 +70,7 @@ trait ConvertsDataTypes if (!is_scalar($entry)) { return ''; } - return $this->clearString((string)$entry, false); + return (string) $this->clearString((string)$entry, false); } /** @@ -199,7 +199,7 @@ trait ConvertsDataTypes */ public function stringWithNewlines(string $field): string { - return $this->clearString((string)($this->get($field) ?? '')); + return (string) $this->clearString((string)($this->get($field) ?? '')); } /** @@ -255,7 +255,7 @@ trait ConvertsDataTypes */ protected function convertDateTime(?string $string): ?Carbon { - $value = $this->get($string); + $value = $this->get((string)$string); if (null === $value) { return null; } diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index c8b246e194..d2a290618a 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -36,7 +36,6 @@ use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Services\Password\Verifier; -use FireflyIII\Support\Facades\Preferences; use FireflyIII\Support\ParseDateString; use FireflyIII\TransactionRules\Triggers\TriggerInterface; use FireflyIII\User; @@ -49,6 +48,7 @@ use ValueError; /** * Class FireflyValidator. + * TODO all of these validations must become separate classes. */ class FireflyValidator extends Validator { @@ -60,6 +60,7 @@ class FireflyValidator extends Validator * @throws IncompatibleWithGoogleAuthenticatorException * @throws InvalidCharactersException * @throws SecretKeyTooShortException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function validate2faCode($attribute, $value): bool { @@ -73,18 +74,18 @@ class FireflyValidator extends Validator } $secretPreference = app('preferences')->get('temp-mfa-secret'); $secret = $secretPreference?->data ?? ''; - if(is_array($secret)) { + if (is_array($secret)) { $secret = ''; } - return (bool) Google2FA::verifyKey((string) $secret, $value); + return (bool)Google2FA::verifyKey((string)$secret, $value); } /** * @param mixed $attribute * @param mixed $value * @param mixed $parameters - * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @return bool */ public function validateBelongsToUser($attribute, $value, $parameters): bool @@ -102,7 +103,7 @@ class FireflyValidator extends Validator /** * @param mixed $attribute * @param mixed $value - * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @return bool */ public function validateBic($attribute, $value): bool @@ -122,7 +123,7 @@ class FireflyValidator extends Validator /** * @param mixed $attribute * @param mixed $value - * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @return bool */ public function validateIban(mixed $attribute, mixed $value): bool @@ -186,7 +187,7 @@ class FireflyValidator extends Validator $value = strtoupper($value); // replace characters outside of ASCI range. - $value = (string) iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value); + $value = (string)iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value); $search = [' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; $replace = [ '', @@ -228,7 +229,8 @@ class FireflyValidator extends Validator } try { $checksum = bcmod($iban, '97'); - } catch (ValueError $e) { /** @phpstan-ignore-line */ + } catch (ValueError $e) { + /** @phpstan-ignore-line */ $message = sprintf('Could not validate IBAN check value "%s" (IBAN "%s")', $iban, $value); app('log')->error($message); app('log')->error($e->getTraceAsString()); @@ -243,7 +245,7 @@ class FireflyValidator extends Validator * @param mixed $attribute * @param mixed $value * @param mixed $parameters - * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @return bool */ public function validateLess($attribute, $value, $parameters): bool @@ -258,7 +260,7 @@ class FireflyValidator extends Validator * @param mixed $attribute * @param mixed $value * @param mixed $parameters - * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @return bool */ public function validateMore($attribute, $value, $parameters): bool @@ -273,7 +275,7 @@ class FireflyValidator extends Validator * @param mixed $attribute * @param mixed $value * @param mixed $parameters - * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @return bool */ public function validateMustExist($attribute, $value, $parameters): bool @@ -444,7 +446,7 @@ class FireflyValidator extends Validator /** * @param mixed $attribute * @param mixed $value - * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @return bool */ public function validateSecurePassword($attribute, $value): bool @@ -467,6 +469,7 @@ class FireflyValidator extends Validator * @param mixed $attribute * @param mixed $value * @param mixed $parameters + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @return bool */ @@ -512,7 +515,7 @@ class FireflyValidator extends Validator if (!array_key_exists('user_id', $this->data)) { return false; } - + /** @var User $user */ $user = User::find($this->data['user_id']); $type = AccountType::find($this->data['account_type_id'])->first(); @@ -624,6 +627,7 @@ class FireflyValidator extends Validator * @param mixed $attribute * @param mixed $value * @param mixed $parameters + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @return bool */ @@ -676,10 +680,11 @@ class FireflyValidator extends Validator /** * @param string|null $attribute * @param string|null $value + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @return bool */ - public function validateUniqueCurrencyCode(string|null $attribute, string|null $value): bool + public function validateUniqueCurrencyCode(string | null $attribute, string | null $value): bool { return $this->validateUniqueCurrency('code', (string)$attribute, (string)$value); } @@ -688,6 +693,7 @@ class FireflyValidator extends Validator * @param string $field * @param string $attribute * @param string $value + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @return bool */ @@ -702,7 +708,7 @@ class FireflyValidator extends Validator * * @return bool */ - public function validateUniqueCurrencyName(string|null $attribute, string|null $value): bool + public function validateUniqueCurrencyName(string | null $attribute, string | null $value): bool { return $this->validateUniqueCurrency('name', (string)$attribute, (string)$value); } @@ -713,7 +719,7 @@ class FireflyValidator extends Validator * * @return bool */ - public function validateUniqueCurrencySymbol(string|null $attribute, string|null $value): bool + public function validateUniqueCurrencySymbol(string | null $attribute, string | null $value): bool { return $this->validateUniqueCurrency('symbol', (string)$attribute, (string)$value); } @@ -722,6 +728,7 @@ class FireflyValidator extends Validator * @param mixed $value * @param mixed $parameters * @param mixed $something + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @return bool */ @@ -777,6 +784,7 @@ class FireflyValidator extends Validator * @param mixed $attribute * @param mixed $value * @param mixed $parameters + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @return bool */ @@ -809,6 +817,7 @@ class FireflyValidator extends Validator * @param mixed $attribute * @param mixed $value * @param mixed $parameters + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @return bool */ @@ -830,6 +839,7 @@ class FireflyValidator extends Validator * @param mixed $attribute * @param mixed $value * @param mixed $parameters + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @return bool */ @@ -849,6 +859,7 @@ class FireflyValidator extends Validator /** * @param mixed $value * @param mixed $parameters + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @return bool */ diff --git a/app/Validation/TransactionValidation.php b/app/Validation/TransactionValidation.php index 1e69266de1..c5b086e6f4 100644 --- a/app/Validation/TransactionValidation.php +++ b/app/Validation/TransactionValidation.php @@ -488,7 +488,7 @@ trait TransactionValidation */ private function getTransactionType(TransactionGroup $group, array $transactions): string { - return $transactions[0]['type'] ?? strtolower($group->transactionJournals()->first()->transactionType->type); + return $transactions[0]['type'] ?? strtolower((string) $group->transactionJournals()->first()?->transactionType->type); } /** @@ -502,13 +502,13 @@ trait TransactionValidation if (1 === $transactionGroup->transactionJournals->count()) { $journal = $transactionGroup->transactionJournals->first(); - return $journal->transactions()->where('amount', '<', 0)->first()->account; + return $journal?->transactions()->where('amount', '<', 0)->first()?->account; } /** @var TransactionJournal $journal */ foreach ($transactionGroup->transactionJournals as $journal) { $journalId = (int)($transaction['transaction_journal_id'] ?? 0); if ($journal->id === $journalId) { - return $journal->transactions()->where('amount', '<', 0)->first()->account; + return $journal->transactions()->where('amount', '<', 0)->first()?->account; } } @@ -785,7 +785,7 @@ trait TransactionValidation } /** @var Transaction|null $destination */ $destination = Transaction::where('transaction_journal_id', $journalId)->where('amount', '>', 0)->with(['account'])->first(); - if (null !== $source) { + if (null !== $destination) { $return['destination_id'] = $destination->account_id; $return['destination_name'] = $destination->account->name; }