Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix phpstan issues.
James Colefa3ccbda3338
diff --git a/app/Api/V2/Controllers/Autocomplete/AccountController.php b/app/Api/V2/Controllers/Autocomplete/AccountController.phpindex 46082d4c79..83b8f560ca 100644--- a/app/Api/V2/Controllers/Autocomplete/AccountController.php+++ b/app/Api/V2/Controllers/Autocomplete/AccountController.php@@ -55,11 +55,7 @@ class AccountController extends Controllerfunction ($request, $next) {$this->repository = app(AccountRepositoryInterface::class);$this->adminRepository = app(AdminAccountRepositoryInterface::class);-- $userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->adminRepository->setUserGroup($userGroup);- }+ $this->adminRepository->setUserGroup($this->validateUserGroup($request));return $next($request);}@@ -85,7 +81,7 @@ class AccountController extends Controller$types = $data['types'];$query = $data['query'];$date = $this->parameters->get('date') ?? today(config('app.timezone'));- $result = $this->adminRepository->searchAccount((string)$query, $types, $data['limit']);+ $result = $this->adminRepository->searchAccount((string) $query, $types, $data['limit']);$defaultCurrency = app('amount')->getDefaultCurrency();$groupedResult = [];$allItems = [];@@ -99,19 +95,19 @@ class AccountController extends Controller$balance = app('steam')->balance($account, $date);$nameWithBalance = sprintf('%s (%s)', $account->name, app('amount')->formatAnything($currency, $balance, false));}- $type = (string)trans(sprintf('firefly.%s', $account->accountType->type));+ $type = (string) trans(sprintf('firefly.%s', $account->accountType->type));$groupedResult[$type] ??= ['group ' => $type,'items' => [],];- $allItems[] = [- 'id' => (string)$account->id,- 'value' => (string)$account->id,+ $allItems[] = [+ 'id' => (string) $account->id,+ 'value' => (string) $account->id,'name' => $account->name,'name_with_balance' => $nameWithBalance,'label' => $nameWithBalance,'type' => $account->accountType->type,- 'currency_id' => (string)$currency->id,+ 'currency_id' => (string) $currency->id,'currency_name' => $currency->name,'currency_code' => $currency->code,'currency_symbol' => $currency->symbol,@@ -123,8 +119,8 @@ class AccountController extends Controller$allItems,static function (array $left, array $right): int {$order = [AccountType::ASSET, AccountType::REVENUE, AccountType::EXPENSE];- $posLeft = (int)array_search($left['type'], $order, true);- $posRight = (int)array_search($right['type'], $order, true);+ $posLeft = (int) array_search($left['type'], $order, true);+ $posRight = (int) array_search($right['type'], $order, true);return $posLeft - $posRight;}diff --git a/app/Api/V2/Controllers/Autocomplete/CategoryController.php b/app/Api/V2/Controllers/Autocomplete/CategoryController.phpindex 0df59ffbe2..683cba4b06 100644--- a/app/Api/V2/Controllers/Autocomplete/CategoryController.php+++ b/app/Api/V2/Controllers/Autocomplete/CategoryController.php@@ -45,11 +45,7 @@ class CategoryController extends Controller$this->middleware(function ($request, $next) {$this->repository = app(CategoryRepositoryInterface::class);-- $userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->repository->setUserGroup($userGroup);- }+ $this->repository->setUserGroup($this->validateUserGroup($request));return $next($request);}diff --git a/app/Api/V2/Controllers/Autocomplete/TagController.php b/app/Api/V2/Controllers/Autocomplete/TagController.phpindex 2c977f3bf6..780241cd0f 100644--- a/app/Api/V2/Controllers/Autocomplete/TagController.php+++ b/app/Api/V2/Controllers/Autocomplete/TagController.php@@ -45,11 +45,7 @@ class TagController extends Controller$this->middleware(function ($request, $next) {$this->repository = app(TagRepositoryInterface::class);-- $userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->repository->setUserGroup($userGroup);- }+ $this->repository->setUserGroup($this->validateUserGroup($request));return $next($request);}diff --git a/app/Api/V2/Controllers/Autocomplete/TransactionController.php b/app/Api/V2/Controllers/Autocomplete/TransactionController.phpindex e255adfe1b..fa49140af1 100644--- a/app/Api/V2/Controllers/Autocomplete/TransactionController.php+++ b/app/Api/V2/Controllers/Autocomplete/TransactionController.php@@ -45,11 +45,7 @@ class TransactionController extends Controller$this->middleware(function ($request, $next) {$this->repository = app(JournalRepositoryInterface::class);-- $userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->repository->setUserGroup($userGroup);- }+ $this->repository->setUserGroup($this->validateUserGroup($request));return $next($request);}diff --git a/app/Api/V2/Controllers/Chart/AccountController.php b/app/Api/V2/Controllers/Chart/AccountController.phpindex b51be609b2..109751e091 100644--- a/app/Api/V2/Controllers/Chart/AccountController.php+++ b/app/Api/V2/Controllers/Chart/AccountController.php@@ -55,8 +55,7 @@ class AccountController extends Controller$this->middleware(function ($request, $next) {$this->repository = app(AccountRepositoryInterface::class);- $userGroup = $this->validateUserGroup($request);- $this->repository->setUserGroup($userGroup);+ $this->repository->setUserGroup($this->validateUserGroup($request));return $next($request);}diff --git a/app/Api/V2/Controllers/Chart/BudgetController.php b/app/Api/V2/Controllers/Chart/BudgetController.phpindex 72987816f4..a7ee6ccb3e 100644--- a/app/Api/V2/Controllers/Chart/BudgetController.php+++ b/app/Api/V2/Controllers/Chart/BudgetController.php@@ -64,12 +64,9 @@ class BudgetController extends Controller$this->blRepository = app(BudgetLimitRepositoryInterface::class);$this->opsRepository = app(OperationsRepositoryInterface::class);$this->currency = app('amount')->getDefaultCurrency();-$userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->repository->setUserGroup($userGroup);- $this->opsRepository->setUserGroup($userGroup);- }+ $this->repository->setUserGroup($userGroup);+ $this->opsRepository->setUserGroup($userGroup);return $next($request);}@@ -81,13 +78,13 @@ class BudgetController extends Controller*/public function dashboard(DateRequest $request): JsonResponse{- $params = $request->getAll();+ $params = $request->getAll();/** @var Carbon $start */- $start = $params['start'];+ $start = $params['start'];/** @var Carbon $end */- $end = $params['end'];+ $end = $params['end'];// code from FrontpageChartGenerator, but not in separate class$budgets = $this->repository->getActiveBudgets();@@ -124,11 +121,11 @@ class BudgetController extends Controllerforeach ($rows as $row) {$current = ['label' => $budget->name,- 'currency_id' => (string)$row['currency_id'],+ 'currency_id' => (string) $row['currency_id'],'currency_code' => $row['currency_code'],'currency_name' => $row['currency_name'],'currency_decimal_places' => $row['currency_decimal_places'],- 'native_currency_id' => (string)$row['native_currency_id'],+ 'native_currency_id' => (string) $row['native_currency_id'],'native_currency_code' => $row['native_currency_code'],'native_currency_name' => $row['native_currency_name'],'native_currency_decimal_places' => $row['native_currency_decimal_places'],@@ -189,12 +186,12 @@ class BudgetController extends Controllerforeach ($array as $currencyId => $block) {$this->currencies[$currencyId] ??= TransactionCurrency::find($currencyId);$return[$currencyId] ??= [- 'currency_id' => (string)$currencyId,+ 'currency_id' => (string) $currencyId,'currency_code' => $block['currency_code'],'currency_name' => $block['currency_name'],'currency_symbol' => $block['currency_symbol'],- 'currency_decimal_places' => (int)$block['currency_decimal_places'],- 'native_currency_id' => (string)$this->currency->id,+ 'currency_decimal_places' => (int) $block['currency_decimal_places'],+ 'native_currency_id' => (string) $this->currency->id,'native_currency_code' => $this->currency->code,'native_currency_name' => $this->currency->name,'native_currency_symbol' => $this->currency->symbol,@@ -208,14 +205,14 @@ class BudgetController extends Controller'overspent' => '0','native_overspent' => '0',];- $currentBudgetArray = $block['budgets'][$budgetId];+ $currentBudgetArray = $block['budgets'][$budgetId];// var_dump($return);/** @var array $journal */foreach ($currentBudgetArray['transaction_journals'] as $journal) {// convert the amount to the native currency.- $rate = $converter->getCurrencyRate($this->currencies[$currencyId], $this->currency, $journal['date']);- $convertedAmount = bcmul($journal['amount'], $rate);+ $rate = $converter->getCurrencyRate($this->currencies[$currencyId], $this->currency, $journal['date']);+ $convertedAmount = bcmul($journal['amount'], $rate);if ($journal['foreign_currency_id'] === $this->currency->id) {$convertedAmount = $journal['foreign_amount'];}@@ -258,7 +255,7 @@ class BudgetController extends Controllerprivate function processLimit(Budget $budget, BudgetLimit $limit): array{Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));- $end = clone $limit->end_date;+ $end = clone $limit->end_date;$end->endOfDay();$spent = $this->opsRepository->listExpenses($limit->start_date, $end, null, new Collection([$budget]));$limitCurrencyId = $limit->transaction_currency_id;@@ -276,7 +273,7 @@ class BudgetController extends Controller$filtered[$currencyId] = $entry;}}- $result = $this->processExpenses($budget->id, $filtered, $limit->start_date, $end);+ $result = $this->processExpenses($budget->id, $filtered, $limit->start_date, $end);if (1 === count($result)) {$compare = bccomp($limit->amount, app('steam')->positive($result[$limitCurrencyId]['spent']));if (1 === $compare) {diff --git a/app/Api/V2/Controllers/Chart/CategoryController.php b/app/Api/V2/Controllers/Chart/CategoryController.phpindex 09124d9a8c..a59e0b62fe 100644--- a/app/Api/V2/Controllers/Chart/CategoryController.php+++ b/app/Api/V2/Controllers/Chart/CategoryController.php@@ -57,10 +57,7 @@ class CategoryController extends Controllerfunction ($request, $next) {$this->accountRepos = app(AccountRepositoryInterface::class);$this->currencyRepos = app(CurrencyRepositoryInterface::class);- $userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->accountRepos->setUserGroup($userGroup);- }+ $this->accountRepos->setUserGroup($this->validateUserGroup($request));return $next($request);}@@ -80,7 +77,7 @@ class CategoryController extends ControllerLog::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));/** @var Carbon $start */- $start = $this->parameters->get('start');+ $start = $this->parameters->get('start');/** @var Carbon $end */$end = $this->parameters->get('end');@@ -92,33 +89,33 @@ class CategoryController extends Controller// get journals for entire period:/** @var GroupCollectorInterface $collector */- $collector = app(GroupCollectorInterface::class);+ $collector = app(GroupCollectorInterface::class);$collector->setRange($start, $end)->withAccountInformation();$collector->setXorAccounts($accounts)->withCategoryInformation();$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::RECONCILIATION]);- $journals = $collector->getExtractedJournals();+ $journals = $collector->getExtractedJournals();/** @var array $journal */foreach ($journals as $journal) {- $currencyId = (int)$journal['currency_id'];- $currency = $currencies[$currencyId] ?? $this->currencyRepos->find($currencyId);- $currencies[$currencyId] = $currency;- $categoryName = null === $journal['category_name'] ? (string)trans('firefly.no_category') : $journal['category_name'];- $amount = app('steam')->positive($journal['amount']);- $nativeAmount = $converter->convert($default, $currency, $journal['date'], $amount);- $key = sprintf('%s-%s', $categoryName, $currency->code);- if ((int)$journal['foreign_currency_id'] === $default->id) {+ $currencyId = (int) $journal['currency_id'];+ $currency = $currencies[$currencyId] ?? $this->currencyRepos->find($currencyId);+ $currencies[$currencyId] = $currency;+ $categoryName = null === $journal['category_name'] ? (string) trans('firefly.no_category') : $journal['category_name'];+ $amount = app('steam')->positive($journal['amount']);+ $nativeAmount = $converter->convert($default, $currency, $journal['date'], $amount);+ $key = sprintf('%s-%s', $categoryName, $currency->code);+ if ((int) $journal['foreign_currency_id'] === $default->id) {$nativeAmount = app('steam')->positive($journal['foreign_amount']);}// create arrays$return[$key] ??= ['label' => $categoryName,- 'currency_id' => (string)$currency->id,+ 'currency_id' => (string) $currency->id,'currency_code' => $currency->code,'currency_name' => $currency->name,'currency_symbol' => $currency->symbol,'currency_decimal_places' => $currency->decimal_places,- 'native_currency_id' => (string)$default->id,+ 'native_currency_id' => (string) $default->id,'native_currency_code' => $default->code,'native_currency_name' => $default->name,'native_currency_symbol' => $default->symbol,@@ -134,11 +131,11 @@ class CategoryController extends Controller$return[$key]['amount'] = bcadd($return[$key]['amount'], $amount);$return[$key]['native_amount'] = bcadd($return[$key]['native_amount'], $nativeAmount);}- $return = array_values($return);+ $return = array_values($return);// order by native amountusort($return, static function (array $a, array $b) {- return (float)$a['native_amount'] < (float)$b['native_amount'] ? 1 : -1;+ return (float) $a['native_amount'] < (float) $b['native_amount'] ? 1 : -1;});$converter->summarize();diff --git a/app/Api/V2/Controllers/Model/Account/UpdateController.php b/app/Api/V2/Controllers/Model/Account/UpdateController.phpindex 08b56ab2c9..bd339f86e5 100644--- a/app/Api/V2/Controllers/Model/Account/UpdateController.php+++ b/app/Api/V2/Controllers/Model/Account/UpdateController.php@@ -45,11 +45,7 @@ class UpdateController extends Controller$this->middleware(function ($request, $next) {$this->repository = app(AccountRepositoryInterface::class);- // new way of user group validation- $userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->repository->setUserGroup($userGroup);- }+ $this->repository->setUserGroup($this->validateUserGroup($request));return $next($request);}@@ -63,17 +59,16 @@ class UpdateController extends Controller{app('log')->debug(sprintf('Now in %s', __METHOD__));$data = $request->getUpdateData();- $data['type'] = config('firefly.shortNamesByFullName.'.$account->accountType->type);+ $data['type'] = config('firefly.shortNamesByFullName.' . $account->accountType->type);$account = $this->repository->update($account, $data);$account->refresh();app('preferences')->mark();- $transformer = new AccountTransformer();+ $transformer = new AccountTransformer();$transformer->setParameters($this->parameters);return response()->api($this->jsonApiObject('accounts', $account, $transformer))- ->header('Content-Type', self::CONTENT_TYPE)- ;+ ->header('Content-Type', self::CONTENT_TYPE);}}diff --git a/app/Api/V2/Controllers/Model/Bill/IndexController.php b/app/Api/V2/Controllers/Model/Bill/IndexController.phpindex 3ddc846b36..bb97d1f03f 100644--- a/app/Api/V2/Controllers/Model/Bill/IndexController.php+++ b/app/Api/V2/Controllers/Model/Bill/IndexController.php@@ -46,12 +46,7 @@ class IndexController extends Controller$this->middleware(function ($request, $next) {$this->repository = app(BillRepositoryInterface::class);-- // new way of user group validation- $userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->repository->setUserGroup($userGroup);- }+ $this->repository->setUserGroup($this->validateUserGroup($request));return $next($request);}diff --git a/app/Api/V2/Controllers/Model/Bill/ShowController.php b/app/Api/V2/Controllers/Model/Bill/ShowController.phpindex db6d59e420..3f225b8758 100644--- a/app/Api/V2/Controllers/Model/Bill/ShowController.php+++ b/app/Api/V2/Controllers/Model/Bill/ShowController.php@@ -46,12 +46,7 @@ class ShowController extends Controller$this->middleware(function ($request, $next) {$this->repository = app(BillRepositoryInterface::class);-- // new way of user group validation- $userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->repository->setUserGroup($userGroup);- }+ $this->repository->setUserGroup($this->validateUserGroup($request));return $next($request);}diff --git a/app/Api/V2/Controllers/Model/Bill/SumController.php b/app/Api/V2/Controllers/Model/Bill/SumController.phpindex 76dd2dca96..6995d51729 100644--- a/app/Api/V2/Controllers/Model/Bill/SumController.php+++ b/app/Api/V2/Controllers/Model/Bill/SumController.php@@ -45,11 +45,7 @@ class SumController extends Controller$this->middleware(function ($request, $next) {$this->repository = app(BillRepositoryInterface::class);-- $userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->repository->setUserGroup($userGroup);- }+ $this->repository->setUserGroup($this->validateUserGroup($request));return $next($request);}diff --git a/app/Api/V2/Controllers/Model/PiggyBank/IndexController.php b/app/Api/V2/Controllers/Model/PiggyBank/IndexController.phpindex bdad3f4cf1..8030c3dec5 100644--- a/app/Api/V2/Controllers/Model/PiggyBank/IndexController.php+++ b/app/Api/V2/Controllers/Model/PiggyBank/IndexController.php@@ -46,11 +46,7 @@ class IndexController extends Controller$this->middleware(function ($request, $next) {$this->repository = app(PiggyBankRepositoryInterface::class);-- $userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->repository->setUserGroup($userGroup);- }+ $this->repository->setUserGroup($this->validateUserGroup($request));return $next($request);}diff --git a/app/Api/V2/Controllers/Summary/NetWorthController.php b/app/Api/V2/Controllers/Summary/NetWorthController.phpindex 52921a98f7..441b5abbb8 100644--- a/app/Api/V2/Controllers/Summary/NetWorthController.php+++ b/app/Api/V2/Controllers/Summary/NetWorthController.php@@ -51,11 +51,9 @@ class NetWorthController extends Controller$this->netWorth = app(NetWorthInterface::class);$this->repository = app(AccountRepositoryInterface::class);// new way of user group validation- $userGroup = $this->validateUserGroup($request);- if (null !== $userGroup) {- $this->netWorth->setUserGroup($userGroup);- $this->repository->setUserGroup($userGroup);- }+ $userGroup = $this->validateUserGroup($request);+ $this->netWorth->setUserGroup($userGroup);+ $this->repository->setUserGroup($userGroup);return $next($request);}@@ -81,7 +79,7 @@ class NetWorthController extends Controller);// skip accounts that should not be in the net worth- $result = $this->netWorth->byAccounts($filtered, $date);+ $result = $this->netWorth->byAccounts($filtered, $date);return response()->api($result);}diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.phpindex a6f21bbd39..9536f9d06a 100644--- a/app/Http/Controllers/HomeController.php+++ b/app/Http/Controllers/HomeController.php@@ -151,8 +151,8 @@ class HomeController extends Controller}/** @var Carbon $start */- /** @var Carbon $end */$start = session('start', today(config('app.timezone'))->startOfMonth());+ /** @var Carbon $end */$end = session('end', today(config('app.timezone'))->endOfMonth());$accounts = $repository->getAccountsById($frontpageArray);$today = today(config('app.timezone'));diff --git a/app/Jobs/MailError.php b/app/Jobs/MailError.phpindex 7953f545da..7d838228f8 100644--- a/app/Jobs/MailError.php+++ b/app/Jobs/MailError.php@@ -130,12 +130,12 @@ class MailError extends Job implements ShouldQueue}if (file_exists($file)) {Log::debug(sprintf('Read file in "%s"', $file));- $limits = json_decode(file_get_contents($file), true);+ $limits = json_decode((string)file_get_contents($file), true);}// limit reached?foreach ($types as $type => $info) {Log::debug(sprintf('Now checking limit "%s"', $type), $info);- if (!isset($limits[$type])) {+ if (!array_key_exists($type, $limits)) {Log::debug(sprintf('Limit "%s" reset to zero, did not exist yet.', $type));$limits[$type] = ['time' => time(),diff --git a/app/Support/Http/Api/ValidatesUserGroupTrait.php b/app/Support/Http/Api/ValidatesUserGroupTrait.phpindex a7f6958220..9ea5bf6546 100644--- a/app/Support/Http/Api/ValidatesUserGroupTrait.php+++ b/app/Support/Http/Api/ValidatesUserGroupTrait.php@@ -81,7 +81,7 @@ trait ValidatesUserGroupTraitthrow new AuthorizationException((string) trans('validation.belongs_user_or_user_group'));}Log::debug(sprintf('validateUserGroup: validate access of user to group #%d ("%s").', $groupId, $group->title));- $roles = property_exists($this, 'acceptedRoles') ? $this->acceptedRoles : [];+ $roles = property_exists($this, 'acceptedRoles') ? $this->acceptedRoles : []; // @phpstan-ignore-lineif (0 === count($roles)) {Log::debug('validateUserGroup: no roles defined, so no access.');diff --git a/app/Support/Request/ConvertsDataTypes.php b/app/Support/Request/ConvertsDataTypes.phpindex 331c30304a..6f11ab9b18 100644--- a/app/Support/Request/ConvertsDataTypes.php+++ b/app/Support/Request/ConvertsDataTypes.php@@ -159,9 +159,7 @@ trait ConvertsDataTypesif (method_exists($this, 'validateUserGroup')) { // @phpstan-ignore-line$userGroup = $this->validateUserGroup($this);- if (null !== $userGroup) {$repository->setUserGroup($userGroup);- }}// set administration IDdiff --git a/config/debugbar.php b/config/debugbar.phpindex 9eae9b00fa..12c99a0d7a 100644--- a/config/debugbar.php+++ b/config/debugbar.php@@ -62,7 +62,7 @@ return [|*/- 'editor' => env('DEBUGBAR_EDITOR') ?: env('IGNITION_EDITOR', 'phpstorm'),+ 'editor' => env('DEBUGBAR_EDITOR') ?? env('IGNITION_EDITOR', 'phpstorm'),/*|--------------------------------------------------------------------------