Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix for level 2
James Cole6cd60951ba0e
diff --git a/.ci/phpstan.neon b/.ci/phpstan.neonindex 2582567d74..e4ccccdcf6 100644--- a/.ci/phpstan.neon+++ b/.ci/phpstan.neon@@ -1,7 +1,6 @@parameters:scanFiles:- - ../_ide_helper_models.php- - ../_ide_helper.php+ - ../_ide_helperpaths:- ../app- ../database@@ -17,6 +16,11 @@ parameters:- '#Dynamic call to static method#' # all the Laravel ORM things depend on this.- identifier: varTag.nativeType- identifier: varTag.type+ - '#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#'+ - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::accountTypeIn#'+ - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\BelongsTo::withTrashed#'# - '#Control structures using switch should not be used.#' # switch is fine in some cases.# - '#with no value type specified in iterable type array#' # remove this rule when all other issues are solved.# - '#has no value type specified in iterable type array#' # remove this rule when all other issues are solved.diff --git a/app/Api/V1/Controllers/Controller.php b/app/Api/V1/Controllers/Controller.phpindex 0def2dd2af..a4fa915739 100644--- a/app/Api/V1/Controllers/Controller.php+++ b/app/Api/V1/Controllers/Controller.php@@ -45,7 +45,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;* Class Controller.** @SuppressWarnings("PHPMD.CouplingBetweenObjects")- * @SuppressWarnings(PHPMD.NumberOfChildren)+ * @SuppressWarnings("PHPMD.NumberOfChildren")*/abstract class Controller extends BaseController{diff --git a/app/Api/V2/Controllers/Controller.php b/app/Api/V2/Controllers/Controller.phpindex 2aa1462267..3891b7659e 100644--- a/app/Api/V2/Controllers/Controller.php+++ b/app/Api/V2/Controllers/Controller.php@@ -48,7 +48,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;* Class Controller** @SuppressWarnings("PHPMD.CouplingBetweenObjects")- * @SuppressWarnings(PHPMD.NumberOfChildren)+ * @SuppressWarnings("PHPMD.NumberOfChildren")*/class Controller extends BaseController{diff --git a/app/Console/Commands/Correction/RemovesEmptyGroups.php b/app/Console/Commands/Correction/RemovesEmptyGroups.phpindex 0d68e7f1a2..9058b2f2ab 100644--- a/app/Console/Commands/Correction/RemovesEmptyGroups.php+++ b/app/Console/Commands/Correction/RemovesEmptyGroups.php@@ -39,7 +39,7 @@ class RemovesEmptyGroups extends Command/*** Execute the console command.*- * @throws Exception;+ * @throws Exception*/public function handle(): int{diff --git a/app/Console/Commands/Upgrade/RepairsAccountBalances.php b/app/Console/Commands/Upgrade/RepairsAccountBalances.phpindex 0acebbf969..1e35520f09 100644--- a/app/Console/Commands/Upgrade/RepairsAccountBalances.php+++ b/app/Console/Commands/Upgrade/RepairsAccountBalances.php@@ -70,7 +70,6 @@ class RepairsAccountBalances extends Commandprivate function correctBalanceAmounts(): void{- return;- AccountBalanceCalculator::recalculateAll(true);+ AccountBalanceCalculator::recalculateAll(false);}}diff --git a/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php b/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.phpindex e811428a29..0156ff186e 100644--- a/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php+++ b/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php@@ -240,7 +240,7 @@ class UpgradesVariousCurrencyInformation extends Commandprivate function isMultiCurrency(Account $account): bool{- $value = $this->accountRepos->getMetaValue($account, 'is_multi_currency', false);+ $value = $this->accountRepos->getMetaValue($account, 'is_multi_currency');if (false === $value || null === $value) {return false;}diff --git a/app/Entities/AccountBalance.php b/app/Entities/AccountBalance.phpindex 2f27ee183c..b7e6247126 100644--- a/app/Entities/AccountBalance.php+++ b/app/Entities/AccountBalance.php@@ -36,7 +36,7 @@ class AccountBalance{$balance = new self();$balance->id = (string) random_int(1, 1000);- $balance->name = (string) random_int(1, 1000);+ // $balance->name = (string) random_int(1, 1000);$balance->amount = (string) random_int(1, 1000);$balance->currencyId = '1';diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.phpindex 265b2239f7..eacaa061f1 100644--- a/app/Http/Controllers/Controller.php+++ b/app/Http/Controllers/Controller.php@@ -39,7 +39,7 @@ use Route;* Class Controller.** @SuppressWarnings("PHPMD.CouplingBetweenObjects")- * @SuppressWarnings(PHPMD.NumberOfChildren)+ * @SuppressWarnings("PHPMD.NumberOfChildren")*/abstract class Controller extends BaseController{diff --git a/app/Http/Middleware/InterestingMessage.php b/app/Http/Middleware/InterestingMessage.phpindex c1fea3583b..4a4ab920fe 100644--- a/app/Http/Middleware/InterestingMessage.php+++ b/app/Http/Middleware/InterestingMessage.php@@ -30,6 +30,7 @@ use FireflyIII\Models\TransactionCurrency;use FireflyIII\Models\TransactionGroup;use FireflyIII\Models\TransactionJournal;use FireflyIII\Models\Webhook;+use FireflyIII\User;use Illuminate\Http\Request;/**@@ -140,8 +141,10 @@ class InterestingMessage$accountId = $request->get('account_id');$message = $request->get('message');+ /** @var User $user */+ $user = auth()->user();/** @var null|Account $account */- $account = auth()->user()->accounts()->withTrashed()->find($accountId);+ $account = $user->accounts()->withTrashed()->find($accountId);if (null === $account) {return;diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.phpindex 371f0f6e44..fb33823f0a 100644--- a/app/Models/TransactionJournal.php+++ b/app/Models/TransactionJournal.php@@ -192,7 +192,7 @@ class TransactionJournal extends Model/*** Checks if tables are joined.*/- public static function isJoined(Builder $query, string $table): bool+ public static function isJoined(EloquentBuilder $query, string $table): bool{$joins = $query->getQuery()->joins;foreach ($joins as $join) {diff --git a/app/Repositories/Budget/BudgetLimitRepository.php b/app/Repositories/Budget/BudgetLimitRepository.phpindex c976bb6941..1ffc36abb5 100644--- a/app/Repositories/Budget/BudgetLimitRepository.php+++ b/app/Repositories/Budget/BudgetLimitRepository.php@@ -285,6 +285,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface$currency->save();// find the budget:+ /** @var Budget|null $budget */$budget = $this->user->budgets()->find((int) $data['budget_id']);if (null === $budget) {throw new FireflyException('200004: Budget does not exist.');diff --git a/app/Repositories/Journal/JournalAPIRepository.php b/app/Repositories/Journal/JournalAPIRepository.phpindex 617ce8a6e9..f612970d52 100644--- a/app/Repositories/Journal/JournalAPIRepository.php+++ b/app/Repositories/Journal/JournalAPIRepository.php@@ -25,6 +25,7 @@ declare(strict_types=1);namespace FireflyIII\Repositories\Journal;use FireflyIII\Models\Attachment;+use FireflyIII\Models\PiggyBank;use FireflyIII\Models\PiggyBankEvent;use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;@@ -89,7 +90,7 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface$events = $journal->piggyBankEvents()->get();$events->each(static function (PiggyBankEvent $event): void {- $event->piggyBank = $event->piggyBank()->withTrashed()->first();+ $event->piggyBank = PiggyBank::withTrashed()->find($event->piggy_bank_id);});diff --git a/app/Repositories/Journal/JournalCLIRepository.php b/app/Repositories/Journal/JournalCLIRepository.phpindex 53543eb70b..e5c83e891a 100644--- a/app/Repositories/Journal/JournalCLIRepository.php+++ b/app/Repositories/Journal/JournalCLIRepository.php@@ -25,6 +25,7 @@ declare(strict_types=1);namespace FireflyIII\Repositories\Journal;use Carbon\Carbon;+use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use FireflyIII\Support\CacheProperties;use FireflyIII\User;@@ -57,7 +58,9 @@ class JournalCLIRepository implements JournalCLIRepositoryInterfaceif (null !== $budget) {return $budget->id;}- $budget = $journal->transactions()->first()->budgets()->first();+ /** @var Transaction|null $transaction */+ $transaction = $journal->transactions()->first();+ $budget = $transaction?->budgets()->first();if (null !== $budget) {return $budget->id;}@@ -74,7 +77,9 @@ class JournalCLIRepository implements JournalCLIRepositoryInterfaceif (null !== $category) {return $category->id;}- $category = $journal->transactions()->first()->categories()->first();+ /** @var Transaction|null $transaction */+ $transaction = $journal->transactions()->first();+ $category = $transaction?->categories()->first();if (null !== $category) {return $category->id;}diff --git a/app/Repositories/UserGroups/Currency/CurrencyRepositoryInterface.php b/app/Repositories/UserGroups/Currency/CurrencyRepositoryInterface.phpindex b989d1aa8a..8982498eb4 100644--- a/app/Repositories/UserGroups/Currency/CurrencyRepositoryInterface.php+++ b/app/Repositories/UserGroups/Currency/CurrencyRepositoryInterface.php@@ -26,6 +26,7 @@ namespace FireflyIII\Repositories\UserGroups\Currency;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Models\TransactionCurrency;+use FireflyIII\Models\UserGroup;use FireflyIII\User;use Illuminate\Support\Collection;@@ -33,6 +34,8 @@ interface CurrencyRepositoryInterface{public function currencyInUse(TransactionCurrency $currency): bool;+ public function getUserGroup(): UserGroup;+/*** Currency is in use where exactly.*/diff --git a/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php b/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.phpindex 12150987ac..6c8f789670 100644--- a/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php+++ b/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php@@ -103,4 +103,12 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterfacereturn $object;}++ /**+ * @return Collection+ */+ #[\Override] public function getAll(): Collection+ {+ return $this->userGroup->currencyExchangeRates()->get();+ }}diff --git a/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepositoryInterface.php b/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepositoryInterface.phpindex 3acd4d3d06..ba2c83d9aa 100644--- a/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepositoryInterface.php+++ b/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepositoryInterface.php@@ -33,6 +33,8 @@ interface ExchangeRateRepositoryInterface{public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection;+ public function getAll(): Collection;+public function getSpecificRateOnDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): ?CurrencyExchangeRate;public function deleteRate(CurrencyExchangeRate $rate): void;