Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix phpstan issues.
James Cole7d67fe52f913
diff --git a/app/Api/V1/Controllers/System/UserController.php b/app/Api/V1/Controllers/System/UserController.phpindex 845215cab3..f541855442 100644--- a/app/Api/V1/Controllers/System/UserController.php+++ b/app/Api/V1/Controllers/System/UserController.php@@ -83,8 +83,6 @@ final class UserController extends Controllerthrow new FireflyException('200025: No access to function.');}- public function finishBatch(): JsonResponse {}-/*** This endpoint is documented at:* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/users/listUserdiff --git a/app/Console/Commands/Upgrade/RepairsPostgresSequences.php b/app/Console/Commands/Upgrade/RepairsPostgresSequences.phpindex 8b545364fc..582f47e5e3 100644--- a/app/Console/Commands/Upgrade/RepairsPostgresSequences.php+++ b/app/Console/Commands/Upgrade/RepairsPostgresSequences.php@@ -114,11 +114,11 @@ class RepairsPostgresSequences extends Commandcontinue;}- if ($nextId->nextval < $highestId->max) { // @phpstan-ignore-line+ if ($nextId->nextval < $highestId->max) {DB::select(sprintf('SELECT setval(\'%s_id_seq\', %d)', $tableToCheck, $highestId->max));$highestId = DB::table($tableToCheck)->select(DB::raw('MAX(id)'))->first();$nextId = DB::table($tableToCheck)->select(DB::raw(sprintf('nextval(\'%s_id_seq\')', $tableToCheck)))->first();- if ($nextId->nextval > $highestId->max) { // @phpstan-ignore-line+ if ($nextId->nextval > $highestId->max) {$this->friendlyInfo(sprintf('Table "%s" autoincrement corrected.', $tableToCheck));}if ($nextId->nextval <= $highestId->max) {diff --git a/app/Handlers/Observer/DeletedAccountObserver.php b/app/Handlers/Observer/DeletedAccountObserver.phpindex aa96cedc73..048400896d 100644--- a/app/Handlers/Observer/DeletedAccountObserver.php+++ b/app/Handlers/Observer/DeletedAccountObserver.php@@ -57,8 +57,7 @@ class DeletedAccountObserver$groupIds = TransactionJournal::whereIn('id', $journalIds)->get(['transaction_journals.transaction_group_id'])->pluck('transaction_group_id')- ->toArray() // @phpstan-ignore-line- ;+ ->toArray();if (count($journalIds) > 0) {Transaction::whereIn('transaction_journal_id', $journalIds)->delete();diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.phpindex 0306cca27e..fd77a6625f 100644--- a/app/Http/Controllers/DebugController.php+++ b/app/Http/Controllers/DebugController.php@@ -299,7 +299,7 @@ final class DebugController extends Controllerif ($lastTime > 0) {$carbon = Carbon::createFromTimestamp($lastTime);$lastCronjob = $carbon->format('Y-m-d H:i:s');- $lastCronjobAgo = $carbon->locale('en')->diffForHumans(); // @phpstan-ignore-line+ $lastCronjobAgo = $carbon->locale('en')->diffForHumans();}return [diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.phpindex 36dfb0d282..5395ae2245 100644--- a/app/Http/Middleware/Authenticate.php+++ b/app/Http/Middleware/Authenticate.php@@ -97,32 +97,34 @@ class Authenticatethrow new AuthenticationException('The user is not logged in but must be.', $guards);}}+ throw new FireflyException('This point is generally unreachable.');+//+// exit('five');+// foreach ($guards as $guard) {+// exit('six');+// if ('api' !== $guard) {+// $this->auth->guard($guard)->authenticate();+// }+// $result = $this->auth->guard($guard)->check();+// if ($result) {+// $user = $this->auth->guard($guard)->user();+// $this->validateBlockedUser($user, $guards);+//+// // According to PHPstan the method returns void, but we'll see.+// return $this->auth->shouldUse($guard);+// }+// }+//+// exit('seven');- exit('five');- foreach ($guards as $guard) {- exit('six');- if ('api' !== $guard) {- $this->auth->guard($guard)->authenticate();- }- $result = $this->auth->guard($guard)->check();- if ($result) {- $user = $this->auth->guard($guard)->user();- $this->validateBlockedUser($user, $guards);-- // According to PHPstan the method returns void, but we'll see.- return $this->auth->shouldUse($guard); // @phpstan-ignore-line- }- }-- exit('seven');// this is a massive hack, but if the handler has the oauth exception// at this point we can report its error instead of a generic one.- $message = 'Unauthenticated.';- if (Handler::$lastError instanceof OAuthServerException) {- $message = Handler::$lastError->getHint();- }-- throw new AuthenticationException($message, $guards);+// $message = 'Unauthenticated.';+// if (Handler::$lastError instanceof OAuthServerException) {+// $message = Handler::$lastError->getHint();+// }+//+// throw new AuthenticationException($message, $guards);}/**@@ -144,7 +146,6 @@ class Authenticate// @noinspection PhpUndefinedMethodInspection$this->auth->logout();- // @phpstan-ignore-line (thinks function is undefined)throw new AuthenticationException('Blocked account.', $guards);}Log::debug(sprintf('User #%d is not blocked.', $user->id));diff --git a/app/Jobs/CreateRecurringTransactions.php b/app/Jobs/CreateRecurringTransactions.phpindex 8e77695306..10242e0502 100644--- a/app/Jobs/CreateRecurringTransactions.php+++ b/app/Jobs/CreateRecurringTransactions.php@@ -215,7 +215,7 @@ class CreateRecurringTransactions implements ShouldQueue$single = ['type' => null === $transaction?->transactionType?->type? strtolower((string) $recurrence->transactionType->type)- : strtolower($transaction->transactionType->type), // @phpstan-ignore-line+ : strtolower($transaction->transactionType->type),'date' => $date,'user' => $recurrence->user,'user_group' => $recurrence->user->userGroup,diff --git a/app/Listeners/Model/BudgetLimit/ProcessesBudgetLimits.php b/app/Listeners/Model/BudgetLimit/ProcessesBudgetLimits.phpindex e450f9a27e..f25a8d2cff 100644--- a/app/Listeners/Model/BudgetLimit/ProcessesBudgetLimits.php+++ b/app/Listeners/Model/BudgetLimit/ProcessesBudgetLimits.php@@ -40,6 +40,7 @@ class ProcessesBudgetLimits implements ShouldQueue{public function handle(CreatedBudgetLimit|DestroyedBudgetLimit|UpdatedBudgetLimit $event): void{+ Log::debug(sprintf('Now in handle for event %s', get_class($event)));if ($event instanceof DestroyedBudgetLimit && null !== $event->user) {// need to recalculate all available budgets for this user.$calculator = new AvailableBudgetCalculator();diff --git a/app/Listeners/Model/Subscription/NotifiesAboutOverdueSubscriptions.php b/app/Listeners/Model/Subscription/NotifiesAboutOverdueSubscriptions.phpindex c3a4239f50..ad0f3476da 100644--- a/app/Listeners/Model/Subscription/NotifiesAboutOverdueSubscriptions.php+++ b/app/Listeners/Model/Subscription/NotifiesAboutOverdueSubscriptions.php@@ -70,6 +70,7 @@ class NotifiesAboutOverdueSubscriptions implements ShouldQueuereturn;}+ unset($item);foreach ($toBeWarned as $item) {/** @var Bill $bill */$bill = $item['bill'];diff --git a/app/Listeners/Security/System/HandlesNewUserRegistration.php b/app/Listeners/Security/System/HandlesNewUserRegistration.phpindex e3054d9d79..e7be808c9c 100644--- a/app/Listeners/Security/System/HandlesNewUserRegistration.php+++ b/app/Listeners/Security/System/HandlesNewUserRegistration.php@@ -86,7 +86,7 @@ class HandlesNewUserRegistration implements ShouldQueue$group = null;// create a new group.- while ($groupExists) { // @phpstan-ignore-line+ while ($groupExists) {$groupExists = UserGroup::where('title', $groupTitle)->count() > 0;if (false === $groupExists) {$group = UserGroup::create(['title' => $groupTitle]);diff --git a/app/Listeners/Security/User/NotifiesUserAboutNewIpAddress.php b/app/Listeners/Security/User/NotifiesUserAboutNewIpAddress.phpindex f872e55ff2..e205a02b62 100644--- a/app/Listeners/Security/User/NotifiesUserAboutNewIpAddress.php+++ b/app/Listeners/Security/User/NotifiesUserAboutNewIpAddress.php@@ -40,6 +40,7 @@ class NotifiesUserAboutNewIpAddress implements ShouldQueuereturn; // do not email demo user.}+ /** @var array|null $list */$list = Preferences::getForUser($user, 'login_ip_history', [])->data;if (!is_array($list)) {$list = [];diff --git a/app/Models/Account.php b/app/Models/Account.phpindex 4888430ee3..4fd1786ddb 100644--- a/app/Models/Account.php+++ b/app/Models/Account.php@@ -81,10 +81,6 @@ class Account extends Modelthrow new NotFoundHttpException();}- public function accountBalances(): HasMany- {- return $this->hasMany(AccountBalance::class);- }public function accountMeta(): HasMany{diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.phpindex 7162b56479..055a95b782 100644--- a/app/Repositories/Journal/JournalRepository.php+++ b/app/Repositories/Journal/JournalRepository.php@@ -40,6 +40,7 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;use Illuminate\Support\Collection;use Override;+use function Safe\json_encode;/*** Class JournalRepository.diff --git a/app/Repositories/PeriodStatistic/PeriodStatisticRepositoryInterface.php b/app/Repositories/PeriodStatistic/PeriodStatisticRepositoryInterface.phpindex 5291934ea9..effc726764 100644--- a/app/Repositories/PeriodStatistic/PeriodStatisticRepositoryInterface.php+++ b/app/Repositories/PeriodStatistic/PeriodStatisticRepositoryInterface.php@@ -35,7 +35,7 @@ interface PeriodStatisticRepositoryInterfacepublic function allInRangeForPrefix(string $prefix, Carbon $start, Carbon $end): Collection;- public function deleteStatisticsForCollection(Collection $set);+ public function deleteStatisticsForCollection(Collection $set): void;public function deleteStatisticsForModel(Model $model, Carbon $date): void;diff --git a/app/Services/FireflyIIIOrg/Update/GitHubUpdateRequest.php b/app/Services/FireflyIIIOrg/Update/GitHubUpdateRequest.phpindex 087841d1d8..63a2b796b9 100644--- a/app/Services/FireflyIIIOrg/Update/GitHubUpdateRequest.php+++ b/app/Services/FireflyIIIOrg/Update/GitHubUpdateRequest.php@@ -30,6 +30,8 @@ use GuzzleHttp\Client;use GuzzleHttp\Exception\ClientException;use Illuminate\Support\Facades\Log;use Override;+use function Safe\file_get_contents;+use function Safe\json_decode;class GitHubUpdateRequest implements UpdateRequestInterface{@@ -106,7 +108,7 @@ class GitHubUpdateRequest implements UpdateRequestInterfacereturn $response;}- return $response;+ // return $response;}private function filterReleases(array $releases): arraydiff --git a/app/Services/Internal/Support/CreditRecalculateService.php b/app/Services/Internal/Support/CreditRecalculateService.phpindex c3685c525d..fbd4e2796f 100644--- a/app/Services/Internal/Support/CreditRecalculateService.php+++ b/app/Services/Internal/Support/CreditRecalculateService.php@@ -120,24 +120,6 @@ class CreditRecalculateService}}- /**- * @throws FireflyException- */- private function findByJournal(TransactionJournal $journal): void- {- $source = $this->getSourceAccount($journal);- $destination = $this->getDestinationAccount($journal);-- // destination or source must be liability.- $valid = config('firefly.valid_liabilities');- if (in_array($destination->accountType->type, $valid, true)) {- $this->work[] = $destination;- }- if (in_array($source->accountType->type, $valid, true)) {- $this->work[] = $source;- }- }-/*** @throws FireflyException*/@@ -170,23 +152,6 @@ class CreditRecalculateServicereturn $usedAmount;}-- /**- * @throws FireflyException- */- private function getDestinationAccount(TransactionJournal $journal): Account- {- return $this->getAccountByDirection($journal, '>');- }-- /**- * @throws FireflyException- */- private function getSourceAccount(TransactionJournal $journal): Account- {- return $this->getAccountByDirection($journal, '<');- }-/*** case 4* it's a deposit into this liability (from revenue account).diff --git a/app/Services/Internal/Update/BillUpdateService.php b/app/Services/Internal/Update/BillUpdateService.phpindex 38d7825c4c..2e41265593 100644--- a/app/Services/Internal/Update/BillUpdateService.php+++ b/app/Services/Internal/Update/BillUpdateService.php@@ -120,11 +120,6 @@ class BillUpdateServicereturn $bill;}- private function getRuleTrigger(Rule $rule, string $key): ?RuleTrigger- {- /** @var null|RuleTrigger */- return $rule->ruleTriggers()->where('trigger_type', $key)->first();- }/*** @SuppressWarnings("PHPMD.NPathComplexity")@@ -195,29 +190,4 @@ class BillUpdateService$bill->save();}}-- private function updateRules(Collection $rules, string $key, string $oldValue, string $newValue): void- {- /** @var Rule $rule */- foreach ($rules as $rule) {- $trigger = $this->getRuleTrigger($rule, $key);- if ($trigger instanceof RuleTrigger && $trigger->trigger_value === $oldValue) {- Log::debug(sprintf('Updated rule trigger #%d from value "%s" to value "%s"', $trigger->id, $oldValue, $newValue));- $trigger->trigger_value = $newValue;- $trigger->save();-- continue;- }- if (- $trigger instanceof RuleTrigger- && $trigger->trigger_value !== $oldValue- && in_array($key, ['amount_more', 'amount_less'], true)- && 0 === bccomp($trigger->trigger_value, $oldValue)- ) {- Log::debug(sprintf('Updated rule trigger #%d from value "%s" to value "%s"', $trigger->id, $oldValue, $newValue));- $trigger->trigger_value = $newValue;- $trigger->save();- }- }- }}diff --git a/app/Support/Authentication/RemoteUserGuard.php b/app/Support/Authentication/RemoteUserGuard.phpindex efa97f1a3a..99a0088f6d 100644--- a/app/Support/Authentication/RemoteUserGuard.php+++ b/app/Support/Authentication/RemoteUserGuard.php@@ -41,7 +41,7 @@ class RemoteUserGuard implements Guard{protected Application $application;protected ?User $user = null;- private $tried = false;+ private bool $tried = false;/*** Create a new authentication guard.diff --git a/app/Support/Form/RuleForm.php b/app/Support/Form/RuleForm.phpindex 0f9cff55c3..a141ab2eab 100644--- a/app/Support/Form/RuleForm.php+++ b/app/Support/Form/RuleForm.php@@ -52,7 +52,7 @@ class RuleFormreturn $this->select($name, $array, $value, $options);}- public function ruleGroupListWithEmpty(string $name, $value = null, ?array $options = null): string+ public function ruleGroupListWithEmpty(string $name, mixed $value = null, ?array $options = null): string{$options ??= [];$options['class'] = 'form-control';diff --git a/app/Support/Http/Api/TransactionFilter.php b/app/Support/Http/Api/TransactionFilter.phpindex 107159fc98..78d7e795e4 100644--- a/app/Support/Http/Api/TransactionFilter.php+++ b/app/Support/Http/Api/TransactionFilter.php@@ -31,7 +31,7 @@ use FireflyIII\Enums\TransactionTypeEnum;*/trait TransactionFilter{- protected $transactionTypes = [+ protected array $transactionTypes = ['all' => [TransactionTypeEnum::WITHDRAWAL->value,TransactionTypeEnum::DEPOSIT->value,