Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix various phpstan issues.
James Cole8e0f0b03d8ce
diff --git a/.ci/phpmd/composer.lock b/.ci/phpmd/composer.lockindex 502002a548..63e98f35e1 100644--- a/.ci/phpmd/composer.lock+++ b/.ci/phpmd/composer.lock@@ -472,16 +472,16 @@},{"name": "symfony/dependency-injection",- "version": "v7.0.0",+ "version": "v7.0.1","source": {"type": "git","url": "https://github.com/symfony/dependency-injection.git",- "reference": "71c053f3284a57d611e11bd7d7f1a76de8514a07"+ "reference": "f6667642954bce638733f254c39e5b5700b47ba4"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/71c053f3284a57d611e11bd7d7f1a76de8514a07",- "reference": "71c053f3284a57d611e11bd7d7f1a76de8514a07",+ "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/f6667642954bce638733f254c39e5b5700b47ba4",+ "reference": "f6667642954bce638733f254c39e5b5700b47ba4","shasum": ""},"require": {@@ -532,7 +532,7 @@"description": "Allows you to standardize and centralize the way objects are constructed in your application","homepage": "https://symfony.com","support": {- "source": "https://github.com/symfony/dependency-injection/tree/v7.0.0"+ "source": "https://github.com/symfony/dependency-injection/tree/v7.0.1"},"funding": [{@@ -548,7 +548,7 @@"type": "tidelift"}],- "time": "2023-11-15T15:38:56+00:00"+ "time": "2023-12-01T15:10:06+00:00"},{"name": "symfony/deprecation-contracts",@@ -929,16 +929,16 @@},{"name": "symfony/var-exporter",- "version": "v7.0.0",+ "version": "v7.0.1","source": {"type": "git","url": "https://github.com/symfony/var-exporter.git",- "reference": "d97726e8d254a2d5512b2b4ba204735d84e7167d"+ "reference": "a3d7c877414fcd59ab7075ecdc3b8f9c00f7bcc3"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/symfony/var-exporter/zipball/d97726e8d254a2d5512b2b4ba204735d84e7167d",- "reference": "d97726e8d254a2d5512b2b4ba204735d84e7167d",+ "url": "https://api.github.com/repos/symfony/var-exporter/zipball/a3d7c877414fcd59ab7075ecdc3b8f9c00f7bcc3",+ "reference": "a3d7c877414fcd59ab7075ecdc3b8f9c00f7bcc3","shasum": ""},"require": {@@ -983,7 +983,7 @@"serialize"],"support": {- "source": "https://github.com/symfony/var-exporter/tree/v7.0.0"+ "source": "https://github.com/symfony/var-exporter/tree/v7.0.1"},"funding": [{@@ -999,7 +999,7 @@"type": "tidelift"}],- "time": "2023-11-29T08:40:23+00:00"+ "time": "2023-11-30T11:38:21+00:00"}],"aliases": [],diff --git a/.ci/phpmd/phpmd.xml b/.ci/phpmd/phpmd.xmlindex 9db62a683d..ed62aab519 100644--- a/.ci/phpmd/phpmd.xml+++ b/.ci/phpmd/phpmd.xml@@ -71,7 +71,8 @@<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"><properties><!-- TODO we want to be at a value of 40. But we start high, and drop the bar slowly. -->- <property name="minimum" value="1000"/>+ <property name="minimum" value="100"/>+ <property name="ignore-whitespace" value="true"/></properties></rule><rule ref="rulesets/codesize.xml/ExcessiveParameterList">diff --git a/.ci/phpstan.neon b/.ci/phpstan.neonindex fbdfdfce4b..ac8d1f7205 100644--- a/.ci/phpstan.neon+++ b/.ci/phpstan.neon@@ -55,6 +55,6 @@ parameters:- ../bootstrap/app.php# The level 8 is the highest level. original was 5- # TODO: slowly up the level and fix the issues found.+ # 7 is more than enough, higher just leaves NULL things.level: 7diff --git a/app/Api/V1/Controllers/Data/DestroyController.php b/app/Api/V1/Controllers/Data/DestroyController.phpindex 4f7a211e43..f46a7f26ff 100644--- a/app/Api/V1/Controllers/Data/DestroyController.php+++ b/app/Api/V1/Controllers/Data/DestroyController.php@@ -66,135 +66,34 @@ class DestroyController extends Controller{$objects = $request->getObjects();$this->unused = $request->boolean('unused', false);- switch ($objects) {- default:- throw new FireflyException(sprintf('200033: This endpoint can\'t handle object "%s"', $objects));- case 'budgets':- $this->destroyBudgets();- break;- case 'bills':- $this->destroyBills();- break;- case 'piggy_banks':- $this->destroyPiggyBanks();- break;- case 'rules':- $this->destroyRules();- break;- case 'recurring':- $this->destroyRecurringTransactions();- break;- case 'categories':- $this->destroyCategories();- break;- case 'tags':- $this->destroyTags();- break;- case 'object_groups':- $this->destroyObjectGroups();- break;- case 'not_assets_liabilities':- $this->destroyAccounts(- [- AccountType::BENEFICIARY,- AccountType::CASH,- AccountType::CREDITCARD,- AccountType::DEFAULT,- AccountType::EXPENSE,- AccountType::IMPORT,- AccountType::INITIAL_BALANCE,- AccountType::LIABILITY_CREDIT,- AccountType::RECONCILIATION,- AccountType::REVENUE,- ]- );- break;- case 'accounts':- $this->destroyAccounts(- [- AccountType::ASSET,- AccountType::BENEFICIARY,- AccountType::CASH,- AccountType::CREDITCARD,- AccountType::DEBT,- AccountType::DEFAULT,- AccountType::EXPENSE,- AccountType::IMPORT,- AccountType::INITIAL_BALANCE,- AccountType::LIABILITY_CREDIT,- AccountType::LOAN,- AccountType::MORTGAGE,- AccountType::RECONCILIATION,- AccountType::REVENUE,- ]- );- break;- case 'asset_accounts':- $this->destroyAccounts(- [- AccountType::ASSET,- AccountType::DEFAULT,- ]- );- break;- case 'expense_accounts':- $this->destroyAccounts(- [- AccountType::BENEFICIARY,- AccountType::EXPENSE,- ]- );- break;- case 'revenue_accounts':- $this->destroyAccounts(- [- AccountType::REVENUE,- ]- );- break;- case 'liabilities':- $this->destroyAccounts(- [- AccountType::DEBT,- AccountType::LOAN,- AccountType::MORTGAGE,- AccountType::CREDITCARD,- ]- );- break;- case 'transactions':- $this->destroyTransactions(- [- TransactionType::WITHDRAWAL,- TransactionType::DEPOSIT,- TransactionType::TRANSFER,- TransactionType::RECONCILIATION,- TransactionType::OPENING_BALANCE,- ]- );- break;- case 'withdrawals':- $this->destroyTransactions(- [- TransactionType::WITHDRAWAL,- ]- );- break;- case 'deposits':- $this->destroyTransactions(- [- TransactionType::DEPOSIT,- ]- );- break;- case 'transfers':- $this->destroyTransactions(- [- TransactionType::TRANSFER,- ]- );- break;- }++ $allExceptAssets = [AccountType::BENEFICIARY, AccountType::CASH, AccountType::CREDITCARD, AccountType::DEFAULT, AccountType::EXPENSE, AccountType::IMPORT, AccountType::INITIAL_BALANCE, AccountType::LIABILITY_CREDIT, AccountType::RECONCILIATION, AccountType::REVENUE,];+ $all = [AccountType::ASSET, AccountType::BENEFICIARY, AccountType::CASH, AccountType::CREDITCARD, AccountType::DEBT, AccountType::DEFAULT, AccountType::EXPENSE, AccountType::IMPORT, AccountType::INITIAL_BALANCE, AccountType::LIABILITY_CREDIT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::RECONCILIATION,];+ $liabilities = [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD];+ $transactions = [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER, TransactionType::RECONCILIATION, TransactionType::OPENING_BALANCE,];++ match ($objects) {+ 'budgets' => $this->destroyBudgets(),+ 'bills' => $this->destroyBills(),+ 'piggy_banks' => $this->destroyPiggyBanks(),+ 'rules' => $this->destroyRules(),+ 'recurring' => $this->destroyRecurringTransactions(),+ 'categories' => $this->destroyCategories(),+ 'tags' => $this->destroyTags(),+ 'object_groups' => $this->destroyObjectGroups(),+ 'not_assets_liabilities' => $this->destroyAccounts($allExceptAssets),+ 'accounts' => $this->destroyAccounts($all),+ 'asset_accounts' => $this->destroyAccounts([AccountType::ASSET, AccountType::DEFAULT]),+ 'expense_accounts' => $this->destroyAccounts([AccountType::BENEFICIARY, AccountType::EXPENSE]),+ 'revenue_accounts' => $this->destroyAccounts([AccountType::REVENUE]),+ 'liabilities' => $this->destroyAccounts($liabilities),+ 'transactions' => $this->destroyTransactions($transactions),+ 'withdrawals' => $this->destroyTransactions([TransactionType::WITHDRAWAL]),+ 'deposits' => $this->destroyTransactions([TransactionType::DEPOSIT]),+ 'transfers' => $this->destroyTransactions([TransactionType::TRANSFER]),+ default => throw new FireflyException(sprintf('200033: This endpoint can\'t handle object "%s"', $objects)),+ };+app('preferences')->mark();return response()->json([], 204);diff --git a/app/Api/V1/Requests/Models/Transaction/StoreRequest.php b/app/Api/V1/Requests/Models/Transaction/StoreRequest.phpindex 7a3efa7ee5..b060432b5f 100644--- a/app/Api/V1/Requests/Models/Transaction/StoreRequest.php+++ b/app/Api/V1/Requests/Models/Transaction/StoreRequest.php@@ -98,7 +98,7 @@ class StoreRequest extends FormRequest'foreign_amount' => $this->clearString((string)$object['foreign_amount']),// description.- 'description' => $this->clearString($object['description'], false),+ 'description' => $this->clearString($object['description']),// source of transaction. If everything is null, assume cash account.'source_id' => $this->integerFromValue((string)$object['source_id']),diff --git a/app/Handlers/Events/UserEventHandler.php b/app/Handlers/Events/UserEventHandler.phpindex 70e9698f88..151498839a 100644--- a/app/Handlers/Events/UserEventHandler.php+++ b/app/Handlers/Events/UserEventHandler.php@@ -131,8 +131,7 @@ class UserEventHandler$group = null;// create a new group.- while (true === $groupExists) {- /** @phpstan-ignore-line */+ while (true === $groupExists) { // @phpstan-ignore-line$groupExists = UserGroup::where('title', $groupTitle)->count() > 0;if (false === $groupExists) {$group = UserGroup::create(['title' => $groupTitle]);@@ -206,8 +205,7 @@ class UserEventHandlerif (false === $entry['notified']) {try {Notification::send($user, new UserLogin($ipAddress));- } catch (Exception $e) {- /** @phpstan-ignore-line */+ } catch (Exception $e) {// @phpstan-ignore-line$message = $e->getMessage();if (str_contains($message, 'Bcc')) {app('log')->warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');@@ -241,8 +239,7 @@ class UserEventHandlerif ($repository->hasRole($user, 'owner')) {try {Notification::send($user, new AdminRegistrationNotification($event->user));- } catch (Exception $e) {- /** @phpstan-ignore-line */+ } catch (Exception $e) { // @phpstan-ignore-line$message = $e->getMessage();if (str_contains($message, 'Bcc')) {app('log')->warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');@@ -319,8 +316,7 @@ class UserEventHandler{try {Notification::send($event->user, new UserNewPassword(route('password.reset', [$event->token])));- } catch (Exception $e) {- /** @phpstan-ignore-line */+ } catch (Exception $e) { // @phpstan-ignore-line$message = $e->getMessage();if (str_contains($message, 'Bcc')) {app('log')->warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');@@ -368,8 +364,7 @@ class UserEventHandlerif ($sendMail) {try {Notification::send($event->user, new UserRegistrationNotification());- } catch (Exception $e) {- /** @phpstan-ignore-line */+ } catch (Exception $e) { // @phpstan-ignore-line$message = $e->getMessage();if (str_contains($message, 'Bcc')) {app('log')->warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.phpindex a28b2c764c..030f3edc2a 100644--- a/app/Helpers/Collector/GroupCollector.php+++ b/app/Helpers/Collector/GroupCollector.php@@ -832,7 +832,6 @@ class GroupCollector implements GroupCollectorInterface// and save it (or not) in the new collection.// that new collection is the next current collection/**- * @var int $ii* @var array $item*/foreach ($currentCollection as $item) {diff --git a/app/Repositories/Account/OperationsRepository.php b/app/Repositories/Account/OperationsRepository.phpindex 4779166571..ced842838b 100644--- a/app/Repositories/Account/OperationsRepository.php+++ b/app/Repositories/Account/OperationsRepository.php@@ -272,8 +272,7 @@ class OperationsRepository implements OperationsRepositoryInterface'currency_code' => $journal['currency_code'],'currency_decimal_places' => $journal['currency_decimal_places'],];- $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->$direction($journal['amount']));- /** @phpstan-ignore-line */+ $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->$direction($journal['amount']));// @phpstan-ignore-line// also do foreign amount:$foreignId = (int)$journal['foreign_currency_id'];diff --git a/app/Support/Request/ConvertsDataTypes.php b/app/Support/Request/ConvertsDataTypes.phpindex 0080558456..59765c94c4 100644--- a/app/Support/Request/ConvertsDataTypes.php+++ b/app/Support/Request/ConvertsDataTypes.php@@ -181,8 +181,7 @@ trait ConvertsDataTypes/** @var AccountRepositoryInterface $repository */$repository = app(AccountRepositoryInterface::class);- if (method_exists($this, 'validateUserGroup')) {- /** @phpstan-ignore-line */+ if (method_exists($this, 'validateUserGroup')) { // @phpstan-ignore-line$userGroup = $this->validateUserGroup($this);if (null !== $userGroup) {$repository->setUserGroup($userGroup);diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.phpindex 0a9c84775c..0d1299f83b 100644--- a/app/Support/Search/OperatorQuerySearch.php+++ b/app/Support/Search/OperatorQuerySearch.php@@ -1449,7 +1449,7 @@ class OperatorQuerySearch implements SearchInterface*/private function searchAccountNr(string $value, SearchDirection $searchDirection, StringPosition $stringPosition, bool $prohibited = false): void{- app('log')->debug(sprintf('searchAccountNr(%s, %d, %d)', $value, $searchDirection, $stringPosition));+ app('log')->debug(sprintf('searchAccountNr(%s, %d, %d)', $value, $searchDirection->name, $stringPosition->name));// search direction (default): for source accounts$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::REVENUE];diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.phpindex d2a290618a..5bb8455acc 100644--- a/app/Validation/FireflyValidator.php+++ b/app/Validation/FireflyValidator.php@@ -229,8 +229,7 @@ class FireflyValidator extends Validator}try {$checksum = bcmod($iban, '97');- } catch (ValueError $e) {- /** @phpstan-ignore-line */+ } catch (ValueError $e) { // @phpstan-ignore-line$message = sprintf('Could not validate IBAN check value "%s" (IBAN "%s")', $iban, $value);app('log')->error($message);app('log')->error($e->getTraceAsString());