From 28e7df2527a878787bfe307d5f2369b13bc5c828 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 10 Sep 2025 16:16:31 +0200 Subject: [PATCH] Small php fixes. --- app/Console/Commands/Correction/CorrectsPiggyBanks.php | 2 -- app/Console/Commands/Correction/RestoresOAuthKeys.php | 1 - app/Console/Commands/System/ForcesDecimalSize.php | 4 ++-- app/Console/Commands/Upgrade/UpgradesLiabilitiesEight.php | 1 - app/Exceptions/GracefulNotFoundHandler.php | 4 ---- app/Helpers/Collector/GroupCollector.php | 2 +- app/Helpers/Report/NetWorth.php | 3 --- app/Http/Controllers/Account/CreateController.php | 4 ++-- app/Http/Controllers/Json/BoxController.php | 2 +- app/Http/Controllers/Report/BudgetController.php | 2 +- app/Repositories/Budget/AvailableBudgetRepository.php | 2 +- app/Rules/IsDuplicateTransaction.php | 5 +---- app/Services/Internal/Support/CreditRecalculateService.php | 1 - app/Support/Calendar/Calculator.php | 2 +- app/Support/JsonApi/Enrichments/BudgetLimitEnrichment.php | 5 ++--- app/Support/Models/AccountBalanceCalculator.php | 2 +- app/Support/Repositories/Recurring/FiltersWeekends.php | 3 +-- 17 files changed, 14 insertions(+), 31 deletions(-) diff --git a/app/Console/Commands/Correction/CorrectsPiggyBanks.php b/app/Console/Commands/Correction/CorrectsPiggyBanks.php index 8922629960..66a737532a 100644 --- a/app/Console/Commands/Correction/CorrectsPiggyBanks.php +++ b/app/Console/Commands/Correction/CorrectsPiggyBanks.php @@ -57,8 +57,6 @@ class CorrectsPiggyBanks extends Command $event->transaction_journal_id = null; $event->save(); ++$count; - - continue; } } if (0 !== $count) { diff --git a/app/Console/Commands/Correction/RestoresOAuthKeys.php b/app/Console/Commands/Correction/RestoresOAuthKeys.php index 8eaf3c79a7..599f127395 100644 --- a/app/Console/Commands/Correction/RestoresOAuthKeys.php +++ b/app/Console/Commands/Correction/RestoresOAuthKeys.php @@ -71,7 +71,6 @@ class RestoresOAuthKeys extends Command $this->storeKeysInDB(); $this->friendlyInfo('Stored OAuth keys in database.'); - return; } } diff --git a/app/Console/Commands/System/ForcesDecimalSize.php b/app/Console/Commands/System/ForcesDecimalSize.php index 4b54218f10..91884011ce 100644 --- a/app/Console/Commands/System/ForcesDecimalSize.php +++ b/app/Console/Commands/System/ForcesDecimalSize.php @@ -515,7 +515,7 @@ class ForcesDecimalSize extends Command continue; } // fix $field by rounding it down correctly. - $pow = (float) 10 ** $currency->decimal_places; + $pow = 10.0 ** $currency->decimal_places; $correct = bcdiv((string) round((float) $value * $pow), (string) $pow, 12); $this->friendlyWarning(sprintf('Transaction #%d has amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct)); @@ -546,7 +546,7 @@ class ForcesDecimalSize extends Command continue; } // fix $field by rounding it down correctly. - $pow = (float) 10 ** $currency->decimal_places; + $pow = 10.0 ** $currency->decimal_places; $correct = bcdiv((string) round((float) $value * $pow), (string) $pow, 12); $this->friendlyWarning( sprintf('Transaction #%d has foreign amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct) diff --git a/app/Console/Commands/Upgrade/UpgradesLiabilitiesEight.php b/app/Console/Commands/Upgrade/UpgradesLiabilitiesEight.php index 511d8c4cf4..9a2bf9f048 100644 --- a/app/Console/Commands/Upgrade/UpgradesLiabilitiesEight.php +++ b/app/Console/Commands/Upgrade/UpgradesLiabilitiesEight.php @@ -157,7 +157,6 @@ class UpgradesLiabilitiesEight extends Command $service = new TransactionGroupDestroyService(); $service->destroy($group); - return; } } diff --git a/app/Exceptions/GracefulNotFoundHandler.php b/app/Exceptions/GracefulNotFoundHandler.php index 4ec31dadad..fe0ca9c896 100644 --- a/app/Exceptions/GracefulNotFoundHandler.php +++ b/app/Exceptions/GracefulNotFoundHandler.php @@ -128,10 +128,6 @@ class GracefulNotFoundHandler extends ExceptionHandler return redirect(route('categories.index')); case 'rules.edit': - $request->session()->reflash(); - - return redirect(route('rules.index')); - case 'rule-groups.edit': $request->session()->reflash(); diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php index 8c3195b4c2..abc28ee56f 100644 --- a/app/Helpers/Collector/GroupCollector.php +++ b/app/Helpers/Collector/GroupCollector.php @@ -560,7 +560,7 @@ class GroupCollector implements GroupCollectorInterface } $groups = $this->parseSums($groups); - return new Collection($groups); + return new Collection()->push(...$groups); } /** diff --git a/app/Helpers/Report/NetWorth.php b/app/Helpers/Report/NetWorth.php index b4ad3af965..9aedb38b7e 100644 --- a/app/Helpers/Report/NetWorth.php +++ b/app/Helpers/Report/NetWorth.php @@ -49,7 +49,6 @@ use Illuminate\Support\Facades\Log; class NetWorth implements NetWorthInterface { private AccountRepositoryInterface $accountRepository; - private CurrencyRepositoryInterface $currencyRepos; private User $user; // @phpstan-ignore-line private ?UserGroup $userGroup = null; @@ -131,8 +130,6 @@ class NetWorth implements NetWorthInterface $this->accountRepository = app(AccountRepositoryInterface::class); $this->accountRepository->setUserGroup($userGroup); - $this->currencyRepos = app(CurrencyRepositoryInterface::class); - $this->currencyRepos->setUserGroup($this->userGroup); } #[Deprecated] diff --git a/app/Http/Controllers/Account/CreateController.php b/app/Http/Controllers/Account/CreateController.php index 9098c4e2fa..743c2fdc7a 100644 --- a/app/Http/Controllers/Account/CreateController.php +++ b/app/Http/Controllers/Account/CreateController.php @@ -86,7 +86,7 @@ class CreateController extends Controller 'latitude' => $hasOldInput ? old('location_latitude') : config('firefly.default_location.latitude'), 'longitude' => $hasOldInput ? old('location_longitude') : config('firefly.default_location.longitude'), 'zoom_level' => $hasOldInput ? old('location_zoom_level') : config('firefly.default_location.zoom_level'), - 'has_location' => $hasOldInput ? 'true' === old('location_has_location') : false, + 'has_location' => $hasOldInput && 'true' === old('location_has_location'), ], ]; $liabilityDirections = [ @@ -106,7 +106,7 @@ class CreateController extends Controller 'preFilled', [ 'currency_id' => $this->primaryCurrency->id, - 'include_net_worth' => $hasOldInput ? (bool) $request->old('include_net_worth') : true, + 'include_net_worth' => !$hasOldInput || (bool)$request->old('include_net_worth'), ] ); // issue #8321 diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php index 928432a75d..ce5f520180 100644 --- a/app/Http/Controllers/Json/BoxController.php +++ b/app/Http/Controllers/Json/BoxController.php @@ -171,7 +171,7 @@ class BoxController extends Controller $filtered = $allAccounts->filter( static function (Account $account) use ($accountRepository) { $includeNetWorth = $accountRepository->getMetaValue($account, 'include_net_worth'); - $result = null === $includeNetWorth ? true : '1' === $includeNetWorth; + $result = null === $includeNetWorth || '1' === $includeNetWorth; if (false === $result) { app('log')->debug(sprintf('Will not include "%s" in net worth charts.', $account->name)); } diff --git a/app/Http/Controllers/Report/BudgetController.php b/app/Http/Controllers/Report/BudgetController.php index 2b26e16501..08d1e63032 100644 --- a/app/Http/Controllers/Report/BudgetController.php +++ b/app/Http/Controllers/Report/BudgetController.php @@ -291,7 +291,7 @@ class BudgetController extends Controller $cache->addProperty('budget-period-report'); $cache->addProperty($accounts->pluck('id')->toArray()); if ($cache->has()) { - // return $cache->get(); + return $cache->get(); } $periods = Navigation::listOfPeriods($start, $end); diff --git a/app/Repositories/Budget/AvailableBudgetRepository.php b/app/Repositories/Budget/AvailableBudgetRepository.php index fb789f3ebb..4c01f348c0 100644 --- a/app/Repositories/Budget/AvailableBudgetRepository.php +++ b/app/Repositories/Budget/AvailableBudgetRepository.php @@ -209,7 +209,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U #[Deprecated] public function setAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end, string $amount): AvailableBudget { - /** @var null|AvailableBudget */ + /** @var AvailableBudget|null $availableBudget */ $availableBudget = $this->user->availableBudgets() ->where('transaction_currency_id', $currency->id) ->where('start_date', $start->format('Y-m-d')) diff --git a/app/Rules/IsDuplicateTransaction.php b/app/Rules/IsDuplicateTransaction.php index e0f6d4ac23..b468fc4397 100644 --- a/app/Rules/IsDuplicateTransaction.php +++ b/app/Rules/IsDuplicateTransaction.php @@ -34,15 +34,12 @@ use Closure; */ class IsDuplicateTransaction implements ValidationRule { - private string $value; /** * @SuppressWarnings("PHPMD.UnusedFormalParameter") */ public function validate(string $attribute, mixed $value, Closure $fail): void { - $this->value = $value; - - $fail($this->value); + $fail($value); } } diff --git a/app/Services/Internal/Support/CreditRecalculateService.php b/app/Services/Internal/Support/CreditRecalculateService.php index 62a445bc5c..eb6b33b8d4 100644 --- a/app/Services/Internal/Support/CreditRecalculateService.php +++ b/app/Services/Internal/Support/CreditRecalculateService.php @@ -227,7 +227,6 @@ class CreditRecalculateService $source->save(); $dest->save(); - return; } // Log::debug('Opening balance is valid'); } diff --git a/app/Support/Calendar/Calculator.php b/app/Support/Calendar/Calculator.php index 8d200fba17..a266937f62 100644 --- a/app/Support/Calendar/Calculator.php +++ b/app/Support/Calendar/Calculator.php @@ -70,7 +70,7 @@ class Calculator } self::$intervalMap = new SplObjectStorage(); foreach (Periodicity::cases() as $interval) { - $periodicityClass = __NAMESPACE__."\\Periodicity\\{$interval->name}"; + $periodicityClass = sprintf('%s\\Periodicity\\%s',__NAMESPACE__,$interval->name); self::$intervals[] = $interval->name; self::$intervalMap->attach($interval, new $periodicityClass()); } diff --git a/app/Support/JsonApi/Enrichments/BudgetLimitEnrichment.php b/app/Support/JsonApi/Enrichments/BudgetLimitEnrichment.php index a416b839d0..c85d394e5f 100644 --- a/app/Support/JsonApi/Enrichments/BudgetLimitEnrichment.php +++ b/app/Support/JsonApi/Enrichments/BudgetLimitEnrichment.php @@ -47,7 +47,6 @@ class BudgetLimitEnrichment implements EnrichmentInterface private array $notes = []; private Carbon $start; private Carbon $end; - private Collection $budgets; private array $expenses = []; private array $pcExpenses = []; private array $currencyIds = []; @@ -147,11 +146,11 @@ class BudgetLimitEnrichment implements EnrichmentInterface private function collectBudgets(): void { $budgetIds = $this->collection->pluck('budget_id')->unique()->toArray(); - $this->budgets = Budget::whereIn('id', $budgetIds)->get(); + $budgets = Budget::whereIn('id', $budgetIds)->get(); $repository = app(OperationsRepository::class); $repository->setUser($this->user); - $expenses = $repository->collectExpenses($this->start, $this->end, null, $this->budgets, null); + $expenses = $repository->collectExpenses($this->start, $this->end, null, $budgets, null); /** @var BudgetLimit $budgetLimit */ foreach ($this->collection as $budgetLimit) { diff --git a/app/Support/Models/AccountBalanceCalculator.php b/app/Support/Models/AccountBalanceCalculator.php index 436582d7fb..d2a3572b7d 100644 --- a/app/Support/Models/AccountBalanceCalculator.php +++ b/app/Support/Models/AccountBalanceCalculator.php @@ -206,7 +206,7 @@ class AccountBalanceCalculator foreach ($transactionJournal->transactions as $transaction) { $set[$transaction->account_id] = $transaction->account; } - $accounts = new Collection($set); + $accounts = new Collection()->push(...$set); $object->optimizedCalculation($accounts, $transactionJournal->date); } } diff --git a/app/Support/Repositories/Recurring/FiltersWeekends.php b/app/Support/Repositories/Recurring/FiltersWeekends.php index e5befa669f..508e13f638 100644 --- a/app/Support/Repositories/Recurring/FiltersWeekends.php +++ b/app/Support/Repositories/Recurring/FiltersWeekends.php @@ -79,14 +79,13 @@ trait FiltersWeekends ); $return[] = $clone; - continue; } // Log::debug(sprintf('Date is %s, removed from final result', $date->format('D d M Y'))); } // filter unique dates Log::debug(sprintf('Count before filtering: %d', count($dates))); - $collection = new Collection($return); + $collection = new Collection()->push(...$return); $filtered = $collection->unique(); $return = $filtered->toArray();