From d4942efd8e3589b1c0f4aa5208d4343b9d1b94d4 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 4 Jan 2025 08:02:05 +0100 Subject: [PATCH] Fix various level 4 issues [skip ci] --- app/Api/V1/Controllers/Controller.php | 2 +- app/Console/Commands/Correction/ConvertsDatesToUTC.php | 10 +++++++--- app/Console/Commands/Integrity/ReportsSums.php | 5 ----- .../Upgrade/UpgradesVariousCurrencyInformation.php | 2 +- app/Factory/PiggyBankFactory.php | 6 +++--- app/Handlers/Events/Model/PiggyBankEventHandler.php | 2 +- app/Handlers/Observer/AccountObserver.php | 2 +- app/Handlers/Observer/PiggyBankObserver.php | 3 --- app/Http/Controllers/DebugController.php | 2 -- app/Http/Controllers/PiggyBank/AmountController.php | 2 -- app/Http/Controllers/PiggyBank/EditController.php | 2 -- app/Jobs/CreateRecurringTransactions.php | 4 ++-- app/Validation/RecurrenceValidation.php | 4 ++-- 13 files changed, 18 insertions(+), 28 deletions(-) diff --git a/app/Api/V1/Controllers/Controller.php b/app/Api/V1/Controllers/Controller.php index a4fa915739..bf046a8fc5 100644 --- a/app/Api/V1/Controllers/Controller.php +++ b/app/Api/V1/Controllers/Controller.php @@ -116,7 +116,7 @@ abstract class Controller extends BaseController if (null !== $date) { try { $obj = Carbon::parse((string) $date); - } catch (InvalidDateException|InvalidFormatException $e) { + } catch (InvalidFormatException $e) { // don't care app('log')->warning( sprintf( diff --git a/app/Console/Commands/Correction/ConvertsDatesToUTC.php b/app/Console/Commands/Correction/ConvertsDatesToUTC.php index 368d238120..4609f98475 100644 --- a/app/Console/Commands/Correction/ConvertsDatesToUTC.php +++ b/app/Console/Commands/Correction/ConvertsDatesToUTC.php @@ -62,7 +62,11 @@ class ConvertsDatesToUTC extends Command { $this->friendlyWarning('Please do not use this command right now.'); - return 0; + // this variable is ALWAYS en_US. + // stops phpstan complaining about dead code. + if (config('app.fallback_locale') === 'en_US') { + return Command::SUCCESS; + } /** * @var string $model @@ -108,10 +112,10 @@ class ConvertsDatesToUTC extends Command $items->each( function ($item) use ($field, $timezoneField): void { /** @var Carbon $date */ - $date = Carbon::parse($item->{$field}, $item->{$timezoneField}); // @phpstan-ignore-line + $date = Carbon::parse($item->{$field}, $item->{$timezoneField}); // @phpstan-ignore-line $date->setTimezone('UTC'); $item->{$field} = $date->format('Y-m-d H:i:s'); // @phpstan-ignore-line - $item->{$timezoneField} = 'UTC'; // @phpstan-ignore-line + $item->{$timezoneField} = 'UTC'; // @phpstan-ignore-line $item->save(); } ); diff --git a/app/Console/Commands/Integrity/ReportsSums.php b/app/Console/Commands/Integrity/ReportsSums.php index f08c942d3a..819754f819 100644 --- a/app/Console/Commands/Integrity/ReportsSums.php +++ b/app/Console/Commands/Integrity/ReportsSums.php @@ -61,12 +61,7 @@ class ReportsSums extends Command $sum = '' === $sum ? '0' : $sum; $foreign = '' === $foreign ? '0' : $foreign; $total = bcadd($sum, $foreign); - if (!is_numeric($total)) { - $message = sprintf('Error: Transactions for user #%d (%s) have an invalid sum ("%s").', $user->id, $user->email, $total); - $this->friendlyError($message); - continue; - } if (0 !== bccomp($total, '0')) { $message = sprintf('Error: Transactions for user #%d (%s) are off by %s!', $user->id, $user->email, $total); $this->friendlyError($message); diff --git a/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php b/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php index ee4ba67ada..0283e00d7c 100644 --- a/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php +++ b/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php @@ -240,7 +240,7 @@ class UpgradesVariousCurrencyInformation extends Command private function isMultiCurrency(Account $account): bool { $value = $this->accountRepos->getMetaValue($account, 'is_multi_currency'); - if (false === $value || null === $value) { + if (null === $value) { return false; } diff --git a/app/Factory/PiggyBankFactory.php b/app/Factory/PiggyBankFactory.php index 6755df9559..199f324b75 100644 --- a/app/Factory/PiggyBankFactory.php +++ b/app/Factory/PiggyBankFactory.php @@ -230,8 +230,8 @@ class PiggyBankFactory foreach ($accounts as $info) { if ($account->id === $info['account_id']) { if (array_key_exists($account->id, $accounts)) { - $toBeLinked[$account->id] = ['current_amount' => $account->pivot?->current_amount ?? '0']; - Log::debug(sprintf('Prefilled for account #%d with amount %s', $account->id, $account->pivot?->current_amount ?? '0')); + $toBeLinked[$account->id] = ['current_amount' => $account->pivot->current_amount ?? '0']; + Log::debug(sprintf('Prefilled for account #%d with amount %s', $account->id, $account->pivot->current_amount ?? '0')); } } } @@ -246,7 +246,7 @@ class PiggyBankFactory } if (array_key_exists('current_amount', $info)) { $toBeLinked[$account->id] = ['current_amount' => $info['current_amount']]; - Log::debug(sprintf('Will link account #%d with amount %s', $account->id, $account->pivot?->current_amount ?? '0')); + Log::debug(sprintf('Will link account #%d with amount %s', $account->id, $account->pivot->current_amount ?? '0')); } if (!array_key_exists('current_amount', $info)) { $toBeLinked[$account->id] ??= []; diff --git a/app/Handlers/Events/Model/PiggyBankEventHandler.php b/app/Handlers/Events/Model/PiggyBankEventHandler.php index dfa4762fcb..21764cf508 100644 --- a/app/Handlers/Events/Model/PiggyBankEventHandler.php +++ b/app/Handlers/Events/Model/PiggyBankEventHandler.php @@ -39,7 +39,7 @@ class PiggyBankEventHandler if (null !== $event->transactionGroup) { $journal = $event->transactionGroup->transactionJournals()->first(); } - $date = $journal?->date ?? today(config('app.timezone')); + $date = $journal->date ?? today(config('app.timezone')); // sanity check: event must not already exist for this journal and piggy bank. if (null !== $journal) { $exists = PiggyBankEvent::where('piggy_bank_id', $event->piggyBank->id) diff --git a/app/Handlers/Observer/AccountObserver.php b/app/Handlers/Observer/AccountObserver.php index fc839ec78b..1360ca9656 100644 --- a/app/Handlers/Observer/AccountObserver.php +++ b/app/Handlers/Observer/AccountObserver.php @@ -56,7 +56,7 @@ class AccountObserver $account->native_virtual_balance = $converter->convert($currency, $userCurrency, today(), $account->virtual_balance); } - if ('' === (string) $account->virtual_balance || ('' !== (string) $account->virtual_balance && 0 === bccomp($account->virtual_balance, '0'))) { + if ('' === (string) $account->virtual_balance || (0 === bccomp($account->virtual_balance, '0'))) { $account->virtual_balance = null; $account->native_virtual_balance = null; } diff --git a/app/Handlers/Observer/PiggyBankObserver.php b/app/Handlers/Observer/PiggyBankObserver.php index cd8acc327d..824ef86621 100644 --- a/app/Handlers/Observer/PiggyBankObserver.php +++ b/app/Handlers/Observer/PiggyBankObserver.php @@ -71,9 +71,6 @@ class PiggyBankObserver return; } $userCurrency = app('amount')->getDefaultCurrencyByUserGroup($group); - if (null === $userCurrency) { - return; - } $piggyBank->native_target_amount = null; if ($piggyBank->transactionCurrency->id !== $userCurrency->id) { $converter = new ExchangeRateConverter(); diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php index ae65970791..11599e1a09 100644 --- a/app/Http/Controllers/DebugController.php +++ b/app/Http/Controllers/DebugController.php @@ -121,9 +121,7 @@ class DebugController extends Controller echo sprintf('

%s

', $count); } } - exit; - var_dump($return); } /** diff --git a/app/Http/Controllers/PiggyBank/AmountController.php b/app/Http/Controllers/PiggyBank/AmountController.php index b9d4bc29a8..49962722bf 100644 --- a/app/Http/Controllers/PiggyBank/AmountController.php +++ b/app/Http/Controllers/PiggyBank/AmountController.php @@ -41,7 +41,6 @@ use Illuminate\View\View; */ class AmountController extends Controller { - private AccountRepositoryInterface $accountRepos; private PiggyBankRepositoryInterface $piggyRepos; /** @@ -57,7 +56,6 @@ class AmountController extends Controller app('view')->share('mainTitleIcon', 'fa-bullseye'); $this->piggyRepos = app(PiggyBankRepositoryInterface::class); - $this->accountRepos = app(AccountRepositoryInterface::class); return $next($request); } diff --git a/app/Http/Controllers/PiggyBank/EditController.php b/app/Http/Controllers/PiggyBank/EditController.php index f7574e59d9..b8d0b6d6bb 100644 --- a/app/Http/Controllers/PiggyBank/EditController.php +++ b/app/Http/Controllers/PiggyBank/EditController.php @@ -41,7 +41,6 @@ use Illuminate\View\View; */ class EditController extends Controller { - private AccountRepositoryInterface $accountRepository; private AttachmentHelperInterface $attachments; private PiggyBankRepositoryInterface $piggyRepos; @@ -59,7 +58,6 @@ class EditController extends Controller $this->attachments = app(AttachmentHelperInterface::class); $this->piggyRepos = app(PiggyBankRepositoryInterface::class); - $this->accountRepository = app(AccountRepositoryInterface::class); return $next($request); } diff --git a/app/Jobs/CreateRecurringTransactions.php b/app/Jobs/CreateRecurringTransactions.php index 540eff0ba9..bf392a3462 100644 --- a/app/Jobs/CreateRecurringTransactions.php +++ b/app/Jobs/CreateRecurringTransactions.php @@ -396,7 +396,7 @@ class CreateRecurringTransactions implements ShouldQueue // update recurring thing: $recurrence->latest_date = $date; - $recurrence->latest_date_tz = $date?->format('e'); + $recurrence->latest_date_tz = $date->format('e'); $recurrence->save(); return $group; @@ -419,7 +419,7 @@ class CreateRecurringTransactions implements ShouldQueue /** @var RecurrenceTransaction $transaction */ foreach ($transactions as $index => $transaction) { $single = [ - 'type' => null === $transaction?->transactionType?->type ? strtolower($recurrence->transactionType->type) : strtolower($transaction->transactionType->type), + 'type' => null === $transaction->transactionType->type ? strtolower($recurrence->transactionType->type) : strtolower($transaction->transactionType->type), 'date' => $date, 'user' => $recurrence->user_id, 'currency_id' => $transaction->transaction_currency_id, diff --git a/app/Validation/RecurrenceValidation.php b/app/Validation/RecurrenceValidation.php index ebb910bd0e..7c87c20b32 100644 --- a/app/Validation/RecurrenceValidation.php +++ b/app/Validation/RecurrenceValidation.php @@ -265,8 +265,8 @@ trait RecurrenceValidation return; } - $nthDay = (int) ($parameters[0] ?? 0.0); - $dayOfWeek = (int) ($parameters[1] ?? 0.0); + $nthDay = (int) $parameters[0]; + $dayOfWeek = (int) $parameters[1]; if ($nthDay < 1 || $nthDay > 5) { $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));