From 2baac1a6d7de0b56797ffb6317a42905f0eba4a3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 4 Jan 2025 07:10:37 +0100 Subject: [PATCH] Fix phpstan level 3! --- .ci/phpstan.neon | 2 + .../Correction/ConvertsDatesToUTC.php | 14 ---- .../CorrectsOpeningBalanceCurrencies.php | 2 +- .../CorrectsTimezoneInformation.php | 11 ---- .../Commands/Upgrade/UpgradesLiabilities.php | 2 + .../Upgrade/UpgradesTransferCurrencies.php | 2 + .../UpgradesVariousCurrencyInformation.php | 4 +- app/Factory/AccountFactory.php | 2 +- app/Factory/BillFactory.php | 1 + app/Factory/BudgetFactory.php | 1 + app/Factory/CategoryFactory.php | 1 + app/Factory/PiggyBankFactory.php | 64 +++++++++---------- .../Webhook/StandardMessageGenerator.php | 2 +- .../Controllers/Account/ShowController.php | 6 +- .../Controllers/Budget/ShowController.php | 6 +- .../Category/NoCategoryController.php | 6 +- .../Controllers/Category/ShowController.php | 6 +- app/Http/Controllers/DebugController.php | 1 + .../Controllers/PiggyBank/IndexController.php | 3 +- app/Jobs/CreateAutoBudgetLimits.php | 1 + app/Models/AccountMeta.php | 2 - app/Models/Configuration.php | 1 - app/Models/Preference.php | 2 +- app/Models/Recurrence.php | 1 - app/Models/RecurrenceMeta.php | 1 - app/Models/RecurrenceRepetition.php | 1 - app/Models/RecurrenceTransaction.php | 1 - app/Models/RecurrenceTransactionMeta.php | 1 - app/Models/TransactionJournalLink.php | 1 - app/Models/TransactionJournalMeta.php | 1 - app/Policies/AccountPolicy.php | 4 -- app/Policies/BalancePolicy.php | 2 - app/Providers/CurrencyServiceProvider.php | 2 +- .../Account/AccountRepository.php | 7 +- app/Repositories/Bill/BillRepository.php | 2 + .../Budget/AvailableBudgetRepository.php | 4 +- .../Budget/BudgetLimitRepository.php | 1 + app/Repositories/Budget/BudgetRepository.php | 4 +- .../Category/CategoryRepository.php | 2 + .../Journal/JournalRepository.php | 1 + .../ObjectGroup/CreatesObjectGroups.php | 2 + .../PiggyBank/PiggyBankRepository.php | 2 +- app/Repositories/Rule/RuleRepository.php | 2 + .../RuleGroup/RuleGroupRepository.php | 2 + app/Repositories/Tag/TagRepository.php | 13 ++-- .../TransactionGroupRepository.php | 2 + .../UserGroups/Account/AccountRepository.php | 6 +- .../Currency/CurrencyRepository.php | 2 +- .../ExchangeRate/ExchangeRateRepository.php | 1 + app/Rules/Account/IsUniqueAccount.php | 3 +- .../Internal/Update/BillUpdateService.php | 1 + .../Internal/Update/JournalUpdateService.php | 12 ++-- 52 files changed, 113 insertions(+), 113 deletions(-) diff --git a/.ci/phpstan.neon b/.ci/phpstan.neon index e9308c084c..a622c37e28 100644 --- a/.ci/phpstan.neon +++ b/.ci/phpstan.neon @@ -16,6 +16,8 @@ parameters: - '#Dynamic call to static method#' # all the Laravel ORM things depend on this. - identifier: varTag.nativeType - identifier: varTag.type + + # phpstan can't handle this so we ignore them. - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::before#' - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::after#' - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::withTrashed#' diff --git a/app/Console/Commands/Correction/ConvertsDatesToUTC.php b/app/Console/Commands/Correction/ConvertsDatesToUTC.php index b9d03027b1..368d238120 100644 --- a/app/Console/Commands/Correction/ConvertsDatesToUTC.php +++ b/app/Console/Commands/Correction/ConvertsDatesToUTC.php @@ -55,23 +55,9 @@ class ConvertsDatesToUTC extends Command { use ShowsFriendlyMessages; - /** - * The console command description. - * - * @var string - */ protected $description = 'Convert stored dates to UTC.'; - - /** - * The name and signature of the console command. - * - * @var string - */ protected $signature = 'correction:convert-to-utc'; - /** - * Execute the console command. - */ public function handle(): int { $this->friendlyWarning('Please do not use this command right now.'); diff --git a/app/Console/Commands/Correction/CorrectsOpeningBalanceCurrencies.php b/app/Console/Commands/Correction/CorrectsOpeningBalanceCurrencies.php index 0b5b8f8ffe..f147160361 100644 --- a/app/Console/Commands/Correction/CorrectsOpeningBalanceCurrencies.php +++ b/app/Console/Commands/Correction/CorrectsOpeningBalanceCurrencies.php @@ -67,7 +67,7 @@ class CorrectsOpeningBalanceCurrencies extends Command private function getJournals(): Collection { - // @var Collection + /** @var Collection */ return TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') ->whereNull('transaction_journals.deleted_at') ->where('transaction_types.type', TransactionTypeEnum::OPENING_BALANCE->value)->get(['transaction_journals.*']) diff --git a/app/Console/Commands/Correction/CorrectsTimezoneInformation.php b/app/Console/Commands/Correction/CorrectsTimezoneInformation.php index 5b3b110bc6..ff514c0cdf 100644 --- a/app/Console/Commands/Correction/CorrectsTimezoneInformation.php +++ b/app/Console/Commands/Correction/CorrectsTimezoneInformation.php @@ -81,18 +81,7 @@ class CorrectsTimezoneInformation extends Command TransactionJournal::class => ['date'], ]; - /** - * The console command description. - * - * @var string - */ protected $description = 'Make sure all dates have a timezone.'; - - /** - * The name and signature of the console command. - * - * @var string - */ protected $signature = 'correction:timezones'; /** diff --git a/app/Console/Commands/Upgrade/UpgradesLiabilities.php b/app/Console/Commands/Upgrade/UpgradesLiabilities.php index c75ccc6a99..b9214069e6 100644 --- a/app/Console/Commands/Upgrade/UpgradesLiabilities.php +++ b/app/Console/Commands/Upgrade/UpgradesLiabilities.php @@ -138,11 +138,13 @@ class UpgradesLiabilities extends Command private function getSourceTransaction(TransactionJournal $journal): ?Transaction { + /** @var Transaction|null */ return $journal->transactions()->where('amount', '<', 0)->first(); } private function getDestinationTransaction(TransactionJournal $journal): ?Transaction { + /** @var Transaction|null */ return $journal->transactions()->where('amount', '>', 0)->first(); } diff --git a/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.php b/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.php index a48bad8c89..89258d3e77 100644 --- a/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.php +++ b/app/Console/Commands/Upgrade/UpgradesTransferCurrencies.php @@ -208,6 +208,7 @@ class UpgradesTransferCurrencies extends Command private function getSourceTransaction(TransactionJournal $transfer): ?Transaction { + /** @var Transaction|null */ return $transfer->transactions()->where('amount', '<', 0)->first(); } @@ -243,6 +244,7 @@ class UpgradesTransferCurrencies extends Command private function getDestinationTransaction(TransactionJournal $transfer): ?Transaction { + /** @var Transaction|null */ return $transfer->transactions()->where('amount', '>', 0)->first(); } diff --git a/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php b/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php index 0156ff186e..7a5002c3e6 100644 --- a/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php +++ b/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php @@ -175,7 +175,7 @@ class UpgradesVariousCurrencyInformation extends Command */ private function getLeadTransaction(TransactionJournal $journal): ?Transaction { - /** @var Transaction $lead */ + /** @var Transaction|null $lead */ $lead = null; switch ($journal->transactionType->type) { @@ -214,7 +214,7 @@ class UpgradesVariousCurrencyInformation extends Command break; } - + /** @var Transaction|null */ return $lead; } diff --git a/app/Factory/AccountFactory.php b/app/Factory/AccountFactory.php index 4148e7da13..a2d2c4f881 100644 --- a/app/Factory/AccountFactory.php +++ b/app/Factory/AccountFactory.php @@ -160,7 +160,7 @@ class AccountFactory app('log')->debug(sprintf('Now in AccountFactory::find("%s", "%s")', $accountName, $accountType)); $type = AccountType::whereType($accountType)->first(); - // @var Account|null + /** @var Account|null */ return $this->user->accounts()->where('account_type_id', $type->id)->where('name', $accountName)->first(); } diff --git a/app/Factory/BillFactory.php b/app/Factory/BillFactory.php index ae120c4fdb..18a2889fbe 100644 --- a/app/Factory/BillFactory.php +++ b/app/Factory/BillFactory.php @@ -129,6 +129,7 @@ class BillFactory public function findByName(string $name): ?Bill { + /** @var Bill|null */ return $this->user->bills()->whereLike('name', sprintf('%%%s%%', $name))->first(); } diff --git a/app/Factory/BudgetFactory.php b/app/Factory/BudgetFactory.php index 48d424d27d..76cbc66a7d 100644 --- a/app/Factory/BudgetFactory.php +++ b/app/Factory/BudgetFactory.php @@ -63,6 +63,7 @@ class BudgetFactory public function findByName(string $name): ?Budget { + /** @var Budget|null */ return $this->user->budgets()->where('name', $name)->first(); } diff --git a/app/Factory/CategoryFactory.php b/app/Factory/CategoryFactory.php index 91e419d23e..caf095471e 100644 --- a/app/Factory/CategoryFactory.php +++ b/app/Factory/CategoryFactory.php @@ -84,6 +84,7 @@ class CategoryFactory public function findByName(string $name): ?Category { + /** @var Category|null */ return $this->user->categories()->where('name', $name)->first(); } diff --git a/app/Factory/PiggyBankFactory.php b/app/Factory/PiggyBankFactory.php index 831f24b8b8..5835757ce5 100644 --- a/app/Factory/PiggyBankFactory.php +++ b/app/Factory/PiggyBankFactory.php @@ -41,14 +41,7 @@ class PiggyBankFactory { use CreatesObjectGroups; - public User $user { - set(User $value) { - $this->user = $value; - $this->currencyRepository->setUser($value); - $this->accountRepository->setUser($value); - $this->piggyBankRepository->setUser($value); - } - } + public User $user; private AccountRepositoryInterface $accountRepository; private CurrencyRepositoryInterface $currencyRepository; private PiggyBankRepositoryInterface $piggyBankRepository; @@ -60,13 +53,21 @@ class PiggyBankFactory $this->piggyBankRepository = app(PiggyBankRepositoryInterface::class); } + public function setUser(User $user): void + { + $this->user = $user; + $this->currencyRepository->setUser($user); + $this->accountRepository->setUser($user); + $this->piggyBankRepository->setUser($user); + } + /** * Store a piggy bank or come back with an exception. */ public function store(array $data): PiggyBank { - $piggyBankData = $data; + $piggyBankData = $data; // unset some fields unset($piggyBankData['object_group_title'], $piggyBankData['transaction_currency_code'], $piggyBankData['transaction_currency_id'], $piggyBankData['accounts'], $piggyBankData['object_group_id'], $piggyBankData['notes']); @@ -90,11 +91,11 @@ class PiggyBankFactory throw new FireflyException('400005: Could not store new piggy bank.', 0, $e); } - $piggyBank = $this->setOrder($piggyBank, $data); + $piggyBank = $this->setOrder($piggyBank, $data); $this->linkToAccountIds($piggyBank, $data['accounts']); $this->piggyBankRepository->updateNote($piggyBank, $data['notes']); - $objectGroupTitle = $data['object_group_title'] ?? ''; + $objectGroupTitle = $data['object_group_title'] ?? ''; if ('' !== $objectGroupTitle) { $objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle); if (null !== $objectGroup) { @@ -102,7 +103,7 @@ class PiggyBankFactory } } // try also with ID - $objectGroupId = (int) ($data['object_group_id'] ?? 0); + $objectGroupId = (int) ($data['object_group_id'] ?? 0); if (0 !== $objectGroupId) { $objectGroup = $this->findObjectGroupById($objectGroupId); if (null !== $objectGroup) { @@ -110,7 +111,7 @@ class PiggyBankFactory } } Log::debug('Touch piggy bank'); - $piggyBank->encrypted = false; + $piggyBank->encrypted = false; $piggyBank->save(); $piggyBank->touch(); @@ -143,11 +144,10 @@ class PiggyBankFactory // first find by ID: if ($piggyBankId > 0) { $piggyBank = PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id') - ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id') - ->where('accounts.user_id', $this->user->id) - ->where('piggy_banks.id', $piggyBankId) - ->first(['piggy_banks.*']) - ; + ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id') + ->where('accounts.user_id', $this->user->id) + ->where('piggy_banks.id', $piggyBankId) + ->first(['piggy_banks.*']); if (null !== $piggyBank) { return $piggyBank; } @@ -168,17 +168,16 @@ class PiggyBankFactory public function findByName(string $name): ?PiggyBank { return PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id') - ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id') - ->where('accounts.user_id', $this->user->id) - ->where('piggy_banks.name', $name) - ->first(['piggy_banks.*']) - ; + ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id') + ->where('accounts.user_id', $this->user->id) + ->where('piggy_banks.name', $name) + ->first(['piggy_banks.*']); } private function setOrder(PiggyBank $piggyBank, array $data): PiggyBank { $this->resetOrder(); - $order = $this->getMaxOrder() + 1; + $order = $this->getMaxOrder() + 1; if (array_key_exists('order', $data)) { $order = $data['order']; } @@ -193,15 +192,14 @@ class PiggyBankFactory { // TODO duplicate code $set = PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id') - ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id') - ->where('accounts.user_id', $this->user->id) - ->with( - [ - 'objectGroups', - ] - ) - ->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*']) - ; + ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id') + ->where('accounts.user_id', $this->user->id) + ->with( + [ + 'objectGroups', + ] + ) + ->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*']); $current = 1; foreach ($set as $piggyBank) { if ($piggyBank->order !== $current) { diff --git a/app/Generator/Webhook/StandardMessageGenerator.php b/app/Generator/Webhook/StandardMessageGenerator.php index 929988f5e7..2d8770e99d 100644 --- a/app/Generator/Webhook/StandardMessageGenerator.php +++ b/app/Generator/Webhook/StandardMessageGenerator.php @@ -132,7 +132,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface return; case TransactionGroup::class: - // @var TransactionGroup $model + /** @var TransactionGroup $model */ $basicMessage['user_id'] = $model->user->id; break; diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php index badc25693d..1360a462d5 100644 --- a/app/Http/Controllers/Account/ShowController.php +++ b/app/Http/Controllers/Account/ShowController.php @@ -85,11 +85,13 @@ class ShowController extends Controller return $this->redirectAccountToAccount($account); } - // @var Carbon $start $start ??= session('start'); - // @var Carbon $end $end ??= session('end'); + /** @var Carbon $start */ + /** @var Carbon $end */ + + if ($end->lt($start)) { [$start, $end] = [$end, $start]; } diff --git a/app/Http/Controllers/Budget/ShowController.php b/app/Http/Controllers/Budget/ShowController.php index b3ec508d43..27137aa543 100644 --- a/app/Http/Controllers/Budget/ShowController.php +++ b/app/Http/Controllers/Budget/ShowController.php @@ -79,10 +79,12 @@ class ShowController extends Controller */ public function noBudget(Request $request, ?Carbon $start = null, ?Carbon $end = null) { - // @var Carbon $start $start ??= session('start'); - // @var Carbon $end $end ??= session('end'); + + /** @var Carbon $start */ + /** @var Carbon $end */ + $subTitle = trans( 'firefly.without_budget_between', ['start' => $start->isoFormat($this->monthAndDayFormat), 'end' => $end->isoFormat($this->monthAndDayFormat)] diff --git a/app/Http/Controllers/Category/NoCategoryController.php b/app/Http/Controllers/Category/NoCategoryController.php index cf19fcc3ab..323b309f4e 100644 --- a/app/Http/Controllers/Category/NoCategoryController.php +++ b/app/Http/Controllers/Category/NoCategoryController.php @@ -75,10 +75,12 @@ class NoCategoryController extends Controller public function show(Request $request, ?Carbon $start = null, ?Carbon $end = null) { app('log')->debug('Start of noCategory()'); - // @var Carbon $start $start ??= session('start'); - // @var Carbon $end $end ??= session('end'); + + /** @var Carbon $start */ + /** @var Carbon $end */ + $page = (int) $request->get('page'); $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $subTitle = trans( diff --git a/app/Http/Controllers/Category/ShowController.php b/app/Http/Controllers/Category/ShowController.php index 00d6305868..c99370b6cb 100644 --- a/app/Http/Controllers/Category/ShowController.php +++ b/app/Http/Controllers/Category/ShowController.php @@ -74,10 +74,12 @@ class ShowController extends Controller */ public function show(Request $request, Category $category, ?Carbon $start = null, ?Carbon $end = null) { - // @var Carbon $start $start ??= session('start', today(config('app.timezone'))->startOfMonth()); - // @var Carbon $end $end ??= session('end', today(config('app.timezone'))->endOfMonth()); + + /** @var Carbon $start */ + /** @var Carbon $end */ + $subTitleIcon = 'fa-bookmark'; $page = (int) $request->get('page'); $attachments = $this->repository->getAttachments($category); diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php index 4f868317c0..d7c06b02af 100644 --- a/app/Http/Controllers/DebugController.php +++ b/app/Http/Controllers/DebugController.php @@ -67,6 +67,7 @@ class DebugController extends Controller if (!auth()->user()->hasRole('owner')) { throw new NotFoundHttpException(); } + /** @var iterable $routes */ $routes = Route::getRoutes(); $return = []; diff --git a/app/Http/Controllers/PiggyBank/IndexController.php b/app/Http/Controllers/PiggyBank/IndexController.php index d461ec49b5..5f54ed2940 100644 --- a/app/Http/Controllers/PiggyBank/IndexController.php +++ b/app/Http/Controllers/PiggyBank/IndexController.php @@ -179,8 +179,9 @@ class IndexController extends Controller private function mergeAccountsAndPiggies(array $piggyBanks, array $accounts): array { - // @var array $piggyBank + /** @var array $group */ foreach ($piggyBanks as $group) { + /** @var array $piggyBank */ foreach ($group['piggy_banks'] as $piggyBank) { // loop all accounts in this piggy bank subtract the current amount from "left to save" in the $accounts array. /** @var array $piggyAccount */ diff --git a/app/Jobs/CreateAutoBudgetLimits.php b/app/Jobs/CreateAutoBudgetLimits.php index c8a9e7e9b9..8c228a2f1b 100644 --- a/app/Jobs/CreateAutoBudgetLimits.php +++ b/app/Jobs/CreateAutoBudgetLimits.php @@ -203,6 +203,7 @@ class CreateAutoBudgetLimits implements ShouldQueue ) ); + /** @var BudgetLimit|null */ return $budget->budgetlimits() ->where('start_date', $start->format('Y-m-d')) ->where('end_date', $end->format('Y-m-d'))->first() diff --git a/app/Models/AccountMeta.php b/app/Models/AccountMeta.php index 782503ae8c..7aacf17970 100644 --- a/app/Models/AccountMeta.php +++ b/app/Models/AccountMeta.php @@ -40,8 +40,6 @@ class AccountMeta extends Model ]; protected $fillable = ['account_id', 'name', 'data']; - - /** @var string The table to store the data in */ protected $table = 'account_meta'; public function account(): BelongsTo diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index 6f00839247..5028d26ba3 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -41,7 +41,6 @@ class Configuration extends Model 'deleted_at' => 'datetime', ]; - /** @var string The table to store the data in */ protected $table = 'configuration'; /** diff --git a/app/Models/Preference.php b/app/Models/Preference.php index 2f5343ed9a..af9d6d4a78 100644 --- a/app/Models/Preference.php +++ b/app/Models/Preference.php @@ -79,6 +79,7 @@ class Preference extends Model $preference = $user->preferences()->where('id', (int) $value)->first(); } if (null !== $preference) { + /** @var Preference $preference */ return $preference; } $default = config('firefly.default_preferences'); @@ -89,7 +90,6 @@ class Preference extends Model $preference->user_id = (int) $user->id; $preference->user_group_id = in_array($value, $items, true) ? $userGroupId : null; $preference->save(); - return $preference; } } diff --git a/app/Models/Recurrence.php b/app/Models/Recurrence.php index 6c8d4ea497..52e77b7979 100644 --- a/app/Models/Recurrence.php +++ b/app/Models/Recurrence.php @@ -63,7 +63,6 @@ class Recurrence extends Model protected $fillable = ['user_id', 'transaction_type_id', 'title', 'description', 'first_date', 'first_date_tz', 'repeat_until', 'repeat_until_tz', 'latest_date', 'latest_date_tz', 'repetitions', 'apply_rules', 'active']; - /** @var string The table to store the data in */ protected $table = 'recurrences'; /** diff --git a/app/Models/RecurrenceMeta.php b/app/Models/RecurrenceMeta.php index d2ea3e8b0c..bfbea2ba84 100644 --- a/app/Models/RecurrenceMeta.php +++ b/app/Models/RecurrenceMeta.php @@ -48,7 +48,6 @@ class RecurrenceMeta extends Model protected $fillable = ['recurrence_id', 'name', 'value']; - /** @var string The table to store the data in */ protected $table = 'recurrences_meta'; public function recurrence(): BelongsTo diff --git a/app/Models/RecurrenceRepetition.php b/app/Models/RecurrenceRepetition.php index 5f657bf4b6..6261a44952 100644 --- a/app/Models/RecurrenceRepetition.php +++ b/app/Models/RecurrenceRepetition.php @@ -62,7 +62,6 @@ class RecurrenceRepetition extends Model protected $fillable = ['recurrence_id', 'weekend', 'repetition_type', 'repetition_moment', 'repetition_skip']; - /** @var string The table to store the data in */ protected $table = 'recurrences_repetitions'; public function recurrence(): BelongsTo diff --git a/app/Models/RecurrenceTransaction.php b/app/Models/RecurrenceTransaction.php index 85d8d37c45..40c9b2008f 100644 --- a/app/Models/RecurrenceTransaction.php +++ b/app/Models/RecurrenceTransaction.php @@ -60,7 +60,6 @@ class RecurrenceTransaction extends Model 'description', ]; - /** @var string The table to store the data in */ protected $table = 'recurrences_transactions'; public function destinationAccount(): BelongsTo diff --git a/app/Models/RecurrenceTransactionMeta.php b/app/Models/RecurrenceTransactionMeta.php index bc59ee520a..6899a36cd0 100644 --- a/app/Models/RecurrenceTransactionMeta.php +++ b/app/Models/RecurrenceTransactionMeta.php @@ -48,7 +48,6 @@ class RecurrenceTransactionMeta extends Model protected $fillable = ['rt_id', 'name', 'value']; - /** @var string The table to store the data in */ protected $table = 'rt_meta'; public function recurrenceTransaction(): BelongsTo diff --git a/app/Models/TransactionJournalLink.php b/app/Models/TransactionJournalLink.php index a5f47481b2..bc0d79314b 100644 --- a/app/Models/TransactionJournalLink.php +++ b/app/Models/TransactionJournalLink.php @@ -42,7 +42,6 @@ class TransactionJournalLink extends Model 'updated_at' => 'datetime', ]; - /** @var string The table to store the data in */ protected $table = 'journal_links'; /** diff --git a/app/Models/TransactionJournalMeta.php b/app/Models/TransactionJournalMeta.php index 1ea70797cc..ca65121061 100644 --- a/app/Models/TransactionJournalMeta.php +++ b/app/Models/TransactionJournalMeta.php @@ -45,7 +45,6 @@ class TransactionJournalMeta extends Model protected $fillable = ['transaction_journal_id', 'name', 'data', 'hash']; - /** @var string The table to store the data in */ protected $table = 'journal_meta'; /** diff --git a/app/Policies/AccountPolicy.php b/app/Policies/AccountPolicy.php index 6f6044fa1a..02a0d920c3 100644 --- a/app/Policies/AccountPolicy.php +++ b/app/Policies/AccountPolicy.php @@ -42,8 +42,6 @@ class AccountPolicy /** * Everybody can do this, but selection should limit to user. - * - * @return true */ public function viewAny(): bool { @@ -54,8 +52,6 @@ class AccountPolicy /** * Everybody can do this, but selection should limit to user. - * - * @return true */ public function viewUser(User $user, Account $account): bool { diff --git a/app/Policies/BalancePolicy.php b/app/Policies/BalancePolicy.php index 6bcd56f673..665536a906 100644 --- a/app/Policies/BalancePolicy.php +++ b/app/Policies/BalancePolicy.php @@ -39,8 +39,6 @@ class BalancePolicy /** * Everybody can do this, but selection should limit to user. - * - * @return true */ public function viewAny(): bool { diff --git a/app/Providers/CurrencyServiceProvider.php b/app/Providers/CurrencyServiceProvider.php index 601ea77f43..545dfef856 100644 --- a/app/Providers/CurrencyServiceProvider.php +++ b/app/Providers/CurrencyServiceProvider.php @@ -77,7 +77,7 @@ class CurrencyServiceProvider extends ServiceProvider $this->app->bind( ExchangeRateRepositoryInterface::class, static function (Application $app) { - // @var ExchangeRateRepository $repository + /** @var ExchangeRateRepository */ return app(ExchangeRateRepository::class); } ); diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 05267d6b5b..0913d75650 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -120,7 +120,7 @@ class AccountRepository implements AccountRepositoryInterface $dbQuery->whereIn('account_types.type', $types); } - // @var Account|null + /** @var Account|null */ return $dbQuery->first(['accounts.*']); } @@ -134,7 +134,7 @@ class AccountRepository implements AccountRepositoryInterface $query->whereIn('account_types.type', $types); } - // @var Account|null + /** @var Account|null */ return $query->where('iban', $iban)->first(['accounts.*']); } @@ -278,7 +278,7 @@ class AccountRepository implements AccountRepositoryInterface public function getLocation(Account $account): ?Location { - // @var Location|null + /** @var Location|null */ return $account->locations()->first(); } @@ -428,6 +428,7 @@ class AccountRepository implements AccountRepositoryInterface public function find(int $accountId): ?Account { + /** @var Account|null */ return $this->user->accounts()->find($accountId); } diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index 8c35166830..b8bdbf7213 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -142,6 +142,7 @@ class BillRepository implements BillRepositoryInterface */ public function find(int $billId): ?Bill { + /** @var Bill|null */ return $this->user->bills()->find($billId); } @@ -150,6 +151,7 @@ class BillRepository implements BillRepositoryInterface */ public function findByName(string $name): ?Bill { + /** @var Bill|null */ return $this->user->bills()->where('name', $name)->first(['bills.*']); } diff --git a/app/Repositories/Budget/AvailableBudgetRepository.php b/app/Repositories/Budget/AvailableBudgetRepository.php index 45a8d4daba..40b74a7e4d 100644 --- a/app/Repositories/Budget/AvailableBudgetRepository.php +++ b/app/Repositories/Budget/AvailableBudgetRepository.php @@ -103,6 +103,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface */ public function find(TransactionCurrency $currency, Carbon $start, Carbon $end): ?AvailableBudget { + /** @var AvailableBudget|null */ return $this->user->availableBudgets() ->where('transaction_currency_id', $currency->id) ->where('start_date', $start->format('Y-m-d')) @@ -194,6 +195,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface public function getByCurrencyDate(Carbon $start, Carbon $end, TransactionCurrency $currency): ?AvailableBudget { + /** @var AvailableBudget|null */ return $this->user ->availableBudgets() ->where('transaction_currency_id', $currency->id) @@ -207,6 +209,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface */ public function setAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end, string $amount): AvailableBudget { + /** @var AvailableBudget */ $availableBudget = $this->user->availableBudgets() ->where('transaction_currency_id', $currency->id) ->where('start_date', $start->format('Y-m-d')) @@ -223,7 +226,6 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface } $availableBudget->amount = $amount; $availableBudget->save(); - return $availableBudget; } diff --git a/app/Repositories/Budget/BudgetLimitRepository.php b/app/Repositories/Budget/BudgetLimitRepository.php index 1ffc36abb5..203fe91e02 100644 --- a/app/Repositories/Budget/BudgetLimitRepository.php +++ b/app/Repositories/Budget/BudgetLimitRepository.php @@ -324,6 +324,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface public function find(Budget $budget, TransactionCurrency $currency, Carbon $start, Carbon $end): ?BudgetLimit { + /** @var BudgetLimit|null */ return $budget->budgetlimits() ->where('transaction_currency_id', $currency->id) ->where('start_date', $start->format('Y-m-d')) diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 096ffc32fd..7d41044d3b 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -384,6 +384,7 @@ class BudgetRepository implements BudgetRepositoryInterface public function getAutoBudget(Budget $budget): ?AutoBudget { + /** @var AutoBudget|null */ return $budget->autoBudgets()->first(); } @@ -442,6 +443,7 @@ class BudgetRepository implements BudgetRepositoryInterface */ public function find(?int $budgetId = null): ?Budget { + /** @var Budget|null */ return $this->user->budgets()->find($budgetId); } @@ -513,7 +515,7 @@ class BudgetRepository implements BudgetRepositoryInterface return null; } $query = sprintf('%%%s%%', $name); - + /** @var Budget|null */ return $this->user->budgets()->whereLike('name', $query)->first(); } diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index 7501fcbdde..b9aed75534 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -129,6 +129,7 @@ class CategoryRepository implements CategoryRepositoryInterface */ public function find(int $categoryId): ?Category { + /** @var Category|null */ return $this->user->categories()->find($categoryId); } @@ -137,6 +138,7 @@ class CategoryRepository implements CategoryRepositoryInterface */ public function findByName(string $name): ?Category { + /** @var Category|null */ return $this->user->categories()->where('name', $name)->first(['categories.*']); } diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index cac96ff771..d55668c352 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -185,6 +185,7 @@ class JournalRepository implements JournalRepositoryInterface */ public function find(int $journalId): ?TransactionJournal { + /** @var TransactionJournal|null */ return $this->user->transactionJournals()->find($journalId); } diff --git a/app/Repositories/ObjectGroup/CreatesObjectGroups.php b/app/Repositories/ObjectGroup/CreatesObjectGroups.php index 767416456a..1710ca6405 100644 --- a/app/Repositories/ObjectGroup/CreatesObjectGroups.php +++ b/app/Repositories/ObjectGroup/CreatesObjectGroups.php @@ -33,6 +33,7 @@ trait CreatesObjectGroups { protected function findObjectGroupById(int $groupId): ?ObjectGroup { + /** @var ObjectGroup|null */ return $this->user->objectGroups()->where('id', $groupId)->first(); } @@ -66,6 +67,7 @@ trait CreatesObjectGroups protected function findObjectGroup(string $title): ?ObjectGroup { + /** @var ObjectGroup|null */ return $this->user->objectGroups()->where('title', $title)->first(); } } diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.php index 3f5d987fdb..31bb7c8cdb 100644 --- a/app/Repositories/PiggyBank/PiggyBankRepository.php +++ b/app/Repositories/PiggyBank/PiggyBankRepository.php @@ -313,7 +313,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface throw new FireflyException('[b] Piggy bank repetitions are EOL.'); } Log::warning('Piggy bank repetitions are EOL.'); - + /** @var PiggyBankRepetition|null */ return $piggyBank->piggyBankRepetitions()->first(); } diff --git a/app/Repositories/Rule/RuleRepository.php b/app/Repositories/Rule/RuleRepository.php index 05758578a7..9b0323bd00 100644 --- a/app/Repositories/Rule/RuleRepository.php +++ b/app/Repositories/Rule/RuleRepository.php @@ -96,6 +96,7 @@ class RuleRepository implements RuleRepositoryInterface */ public function getFirstRuleGroup(): RuleGroup { + /** @var RuleGroup|null */ return $this->user->ruleGroups()->first(); } @@ -276,6 +277,7 @@ class RuleRepository implements RuleRepositoryInterface public function find(int $ruleId): ?Rule { + /** @var Rule|null */ return $this->user->rules()->find($ruleId); } diff --git a/app/Repositories/RuleGroup/RuleGroupRepository.php b/app/Repositories/RuleGroup/RuleGroupRepository.php index a5d6b57b78..830fe2d018 100644 --- a/app/Repositories/RuleGroup/RuleGroupRepository.php +++ b/app/Repositories/RuleGroup/RuleGroupRepository.php @@ -208,11 +208,13 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface public function find(int $ruleGroupId): ?RuleGroup { + /** @var RuleGroup|null */ return $this->user->ruleGroups()->find($ruleGroupId); } public function findByTitle(string $title): ?RuleGroup { + /** @var RuleGroup|null */ return $this->user->ruleGroups()->where('title', $title)->first(); } diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 712dca3eba..ca945090d0 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -101,18 +101,19 @@ class TagRepository implements TagRepositoryInterface public function find(int $tagId): ?Tag { + /** @var Tag|null */ return $this->user->tags()->find($tagId); } public function findByTag(string $tag): ?Tag { - // @var Tag|null + /** @var Tag|null */ return $this->user->tags()->where('tag', $tag)->first(); } public function firstUseDate(Tag $tag): ?Carbon { - // @var Carbon|null + /** @var Carbon|null */ return $tag->transactionJournals()->orderBy('date', 'ASC')->first()?->date; } @@ -180,7 +181,7 @@ class TagRepository implements TagRepositoryInterface public function lastUseDate(Tag $tag): ?Carbon { - // @var Carbon|null + /** @var Carbon|null */ return $tag->transactionJournals()->orderBy('date', 'DESC')->first()?->date; } @@ -189,13 +190,13 @@ class TagRepository implements TagRepositoryInterface */ public function newestTag(): ?Tag { - // @var Tag|null + /** @var Tag|null */ return $this->user->tags()->whereNotNull('date')->orderBy('date', 'DESC')->first(); } public function oldestTag(): ?Tag { - // @var Tag|null + /** @var Tag|null */ return $this->user->tags()->whereNotNull('date')->orderBy('date', 'ASC')->first(); } @@ -380,7 +381,7 @@ class TagRepository implements TagRepositoryInterface public function getLocation(Tag $tag): ?Location { - // @var Location|null + /** @var Location|null */ return $tag->locations()->first(); } } diff --git a/app/Repositories/TransactionGroup/TransactionGroupRepository.php b/app/Repositories/TransactionGroup/TransactionGroupRepository.php index 349209cd9a..0e3fffa009 100644 --- a/app/Repositories/TransactionGroup/TransactionGroupRepository.php +++ b/app/Repositories/TransactionGroup/TransactionGroupRepository.php @@ -69,6 +69,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface */ public function find(int $groupId): ?TransactionGroup { + /** @var TransactionGroup|null */ return $this->user->transactionGroups()->find($groupId); } @@ -290,6 +291,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface /** @var TransactionJournal $journal */ $journal = $this->user->transactionJournals()->find($journalId); + /** @var Location|null */ return $journal->locations()->first(); } diff --git a/app/Repositories/UserGroups/Account/AccountRepository.php b/app/Repositories/UserGroups/Account/AccountRepository.php index 7035f82b24..58ac999d95 100644 --- a/app/Repositories/UserGroups/Account/AccountRepository.php +++ b/app/Repositories/UserGroups/Account/AccountRepository.php @@ -76,7 +76,7 @@ class AccountRepository implements AccountRepositoryInterface $dbQuery->whereIn('account_types.type', $types); } - // @var Account|null + /** @var Account|null */ return $dbQuery->first(['accounts.*']); } @@ -90,7 +90,7 @@ class AccountRepository implements AccountRepositoryInterface $query->whereIn('account_types.type', $types); } - // @var Account|null + /** @var Account|null */ return $query->where('iban', $iban)->first(['accounts.*']); } @@ -167,7 +167,7 @@ class AccountRepository implements AccountRepositoryInterface if (null === $account) { $account = $this->userGroup->accounts()->find($accountId); } - + /** @var Account|null */ return $account; } diff --git a/app/Repositories/UserGroups/Currency/CurrencyRepository.php b/app/Repositories/UserGroups/Currency/CurrencyRepository.php index 147e6599da..1d1a5a4bef 100644 --- a/app/Repositories/UserGroups/Currency/CurrencyRepository.php +++ b/app/Repositories/UserGroups/Currency/CurrencyRepository.php @@ -199,7 +199,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface return $current; }); - + /** @var Collection */ return $all; } diff --git a/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php b/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php index 6c8f789670..713b07f3e4 100644 --- a/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php +++ b/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php @@ -61,6 +61,7 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface #[\Override] public function getSpecificRateOnDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): ?CurrencyExchangeRate { + /** @var CurrencyExchangeRate|null */ return $this->userGroup->currencyExchangeRates() ->where('from_currency_id', $from->id) diff --git a/app/Rules/Account/IsUniqueAccount.php b/app/Rules/Account/IsUniqueAccount.php index 5a3fa3db9b..d60a1b3954 100644 --- a/app/Rules/Account/IsUniqueAccount.php +++ b/app/Rules/Account/IsUniqueAccount.php @@ -39,9 +39,10 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule protected \Closure $fail; #[\Override] - public function setData(array $data): void + public function setData(array $data): self // @phpstan-ignore-line { $this->data = $data; + return $this; } #[\Override] diff --git a/app/Services/Internal/Update/BillUpdateService.php b/app/Services/Internal/Update/BillUpdateService.php index e2f6044b87..a419499f5d 100644 --- a/app/Services/Internal/Update/BillUpdateService.php +++ b/app/Services/Internal/Update/BillUpdateService.php @@ -250,6 +250,7 @@ class BillUpdateService private function getRuleTrigger(Rule $rule, string $key): ?RuleTrigger { + /** @var RuleTrigger|null */ return $rule->ruleTriggers()->where('trigger_type', $key)->first(); } } diff --git a/app/Services/Internal/Update/JournalUpdateService.php b/app/Services/Internal/Update/JournalUpdateService.php index 5d498c52b7..66c970eda2 100644 --- a/app/Services/Internal/Update/JournalUpdateService.php +++ b/app/Services/Internal/Update/JournalUpdateService.php @@ -238,11 +238,9 @@ class JournalUpdateService private function getSourceTransaction(): Transaction { if (null === $this->sourceTransaction) { - $this->sourceTransaction = $this->transactionJournal->transactions()->with(['account'])->where( - 'amount', - '<', - 0 - )->first(); + /** @var Transaction|null $result */ + $result = $this->transactionJournal->transactions()->with(['account'])->where('amount', '<', 0)->first(); + $this->sourceTransaction = $result; } Log::debug(sprintf('getSourceTransaction: %s', $this->sourceTransaction->amount)); @@ -321,7 +319,9 @@ class JournalUpdateService private function getDestinationTransaction(): Transaction { if (null === $this->destinationTransaction) { - $this->destinationTransaction = $this->transactionJournal->transactions()->where('amount', '>', 0)->first(); + /** @var Transaction|null $result */ + $result = $this->transactionJournal->transactions()->where('amount', '>', 0)->first(); + $this->destinationTransaction = $result; } return $this->destinationTransaction;