Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix phpstan issues
Sander Dorigo0885fb631918
diff --git a/app/Api/V1/Controllers/Insight/Income/TagController.php b/app/Api/V1/Controllers/Insight/Income/TagController.phpindex df99eef909..94be2ae461 100644--- a/app/Api/V1/Controllers/Insight/Income/TagController.php+++ b/app/Api/V1/Controllers/Insight/Income/TagController.php@@ -158,7 +158,10 @@ final class TagController extends Controller'currency_id' => (string) $foreignCurrencyId,'currency_code' => $journal['foreign_currency_code'],];- $response[$foreignKey]['difference'] = bcadd((string) $response[$foreignKey]['difference'], Steam::positive($journal['foreign_amount']));+ $response[$foreignKey]['difference'] = bcadd(+ (string) $response[$foreignKey]['difference'],+ Steam::positive($journal['foreign_amount'])+ );$response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference'];}}diff --git a/app/Api/V1/Controllers/Insight/Transfer/TagController.php b/app/Api/V1/Controllers/Insight/Transfer/TagController.phpindex f92a7aa9f0..b7b85fd376 100644--- a/app/Api/V1/Controllers/Insight/Transfer/TagController.php+++ b/app/Api/V1/Controllers/Insight/Transfer/TagController.php@@ -155,7 +155,10 @@ final class TagController extends Controller'currency_id' => (string) $foreignCurrencyId,'currency_code' => $journal['foreign_currency_code'],];- $response[$foreignKey]['difference'] = bcadd((string) $response[$foreignKey]['difference'], Steam::positive($journal['foreign_amount']));+ $response[$foreignKey]['difference'] = bcadd(+ (string) $response[$foreignKey]['difference'],+ Steam::positive($journal['foreign_amount'])+ );$response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference']; // intentional float}}diff --git a/app/Generator/Webhook/StandardMessageGenerator.php b/app/Generator/Webhook/StandardMessageGenerator.phpindex 9a3e6a197a..7a8e931619 100644--- a/app/Generator/Webhook/StandardMessageGenerator.php+++ b/app/Generator/Webhook/StandardMessageGenerator.php@@ -136,7 +136,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface/** @var WebhookResponseModel $response */$response = $webhook->webhookResponses()->first();- $this->getTriggerTitles($webhook->webhookTriggers()->get());+ // $this->getTriggerTitles($webhook->webhookTriggers()->get());$basicMessage = ['uuid' => $uuid->toString(),'user_id' => 0,@@ -299,17 +299,17 @@ class StandardMessageGenerator implements MessageGeneratorInterfacereturn $response->title;}- private function getTriggerTitles(Collection $collection): array- {- $return = [];-- /** @var WebhookTriggerModel $item */- foreach ($collection as $item) {- $return[] = $item->title;- }-- return array_unique($return);- }+// private function getTriggerTitles(Collection $collection): array+// {+// $return = [];+//+// /** @var WebhookTriggerModel $item */+// foreach ($collection as $item) {+// $return[] = $item->title;+// }+//+// return array_unique($return);+// }private function getWebhooks(): Collection{diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.phpindex 627af1d3ed..7aed9c32fd 100644--- a/app/Http/Controllers/Auth/LoginController.php+++ b/app/Http/Controllers/Auth/LoginController.php@@ -151,12 +151,12 @@ final class LoginController extends Controller*/public function logout(Request $request): RedirectResponse|Response{- $authGuard = config('firefly.authentication_guard');- $logoutUrl = config('firefly.custom_logout_url');+ $authGuard = (string) config('firefly.authentication_guard');+ $logoutUrl = (string) config('firefly.custom_logout_url');if ('remote_user_guard' === $authGuard && '' !== $logoutUrl) {return redirect($logoutUrl);}- if ('remote_user_guard' === $authGuard && '' === $logoutUrl) {+ if ('remote_user_guard' === $authGuard) {session()->flash('error', trans('firefly.cant_logout_guard'));}diff --git a/app/Http/Controllers/Bill/IndexController.php b/app/Http/Controllers/Bill/IndexController.phpindex 2009369ae0..07947c2c85 100644--- a/app/Http/Controllers/Bill/IndexController.php+++ b/app/Http/Controllers/Bill/IndexController.php@@ -255,7 +255,10 @@ final class IndexController extends Controllerif (count($bill['paid_dates']) < count($bill['pay_dates'])) {$count = count($bill['pay_dates']) - count($bill['paid_dates']);if ($count > 0) {- $avg = bcdiv(bcadd((string) $bill['amount_min'], (string) $bill['amount_max']), '2');+ $avg = bcdiv(+ bcadd((string) $bill['amount_min'], (string) $bill['amount_max']),+ '2'+ );$avg = bcmul($avg, (string) $count);$sums[$groupOrder][$currencyId]['total_left_to_pay'] = bcadd($sums[$groupOrder][$currencyId]['total_left_to_pay'], $avg);Log::debug(diff --git a/app/Http/Controllers/Budget/BudgetLimitController.php b/app/Http/Controllers/Budget/BudgetLimitController.phpindex 9632996690..b263d702a2 100644--- a/app/Http/Controllers/Budget/BudgetLimitController.php+++ b/app/Http/Controllers/Budget/BudgetLimitController.php@@ -198,7 +198,13 @@ final class BudgetLimitController extends Controllerif ($request->expectsJson()) {$array = $limit->toArray();// add some extra metadata:- $spentArr = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, null, new Collection()->push($budget), $currency);+ $spentArr = $this->opsRepository->sumExpenses(+ $limit->start_date,+ $limit->end_date,+ null,+ new Collection()->push($budget),+ $currency+ );$array['spent'] = $spentArr[$currency->id]['sum'] ?? '0';$array['left_formatted'] = Amount::formatAnything($limit->transactionCurrency, bcadd($array['spent'], (string) $array['amount']));$array['amount_formatted'] = Amount::formatAnything($limit->transactionCurrency, $limit['amount']);diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.phpindex 674f77fbee..750a88e633 100644--- a/app/Http/Controllers/Budget/IndexController.php+++ b/app/Http/Controllers/Budget/IndexController.php@@ -284,7 +284,10 @@ final class IndexController extends Controllerif (array_key_exists($currency->id, $spentArr) && array_key_exists('sum', $spentArr[$currency->id])) {$array['spent'][$currency->id]['spent'] = $spentArr[$currency->id]['sum'];- $array['spent'][$currency->id]['spent_outside'] = Steam::negative(bcsub($spentInLimits[$currency->id], $spentArr[$currency->id]['sum']));+ $array['spent'][$currency->id]['spent_outside'] = Steam::negative(bcsub(+ $spentInLimits[$currency->id],+ $spentArr[$currency->id]['sum']+ ));$array['spent'][$currency->id]['currency_id'] = $currency->id;$array['spent'][$currency->id]['currency_symbol'] = $currency->symbol;$array['spent'][$currency->id]['currency_decimal_places'] = $currency->decimal_places;diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.phpindex ad724137dc..f4b32fe5c5 100644--- a/app/Http/Controllers/Chart/BudgetController.php+++ b/app/Http/Controllers/Chart/BudgetController.php@@ -539,7 +539,13 @@ final class BudgetController extends Controller}// get spent amount in this period for this currency.- $sum = $this->opsRepository->sumExpenses($currentStart, $currentEnd, $accounts, new Collection()->push($budget), $currency);+ $sum = $this->opsRepository->sumExpenses(+ $currentStart,+ $currentEnd,+ $accounts,+ new Collection()->push($budget),+ $currency+ );$amount = Steam::positive($sum[$currency->id]['sum'] ?? '0');$chartData[0]['entries'][$title] = Steam::bcround($amount, $currency->decimal_places);diff --git a/app/Jobs/CreateAutoBudgetLimits.php b/app/Jobs/CreateAutoBudgetLimits.phpindex 93cf5e9364..d61661dd50 100644--- a/app/Jobs/CreateAutoBudgetLimits.php+++ b/app/Jobs/CreateAutoBudgetLimits.php@@ -122,7 +122,13 @@ class CreateAutoBudgetLimits implements ShouldQueue// if has one, calculate expenses and use that as a base.$repository = app(OperationsRepositoryInterface::class);$repository->setUser($autoBudget->budget->user);- $spent = $repository->sumExpenses($previousStart, $previousEnd, null, new Collection()->push($autoBudget->budget), $autoBudget->transactionCurrency);+ $spent = $repository->sumExpenses(+ $previousStart,+ $previousEnd,+ null,+ new Collection()->push($autoBudget->budget),+ $autoBudget->transactionCurrency+ );$currencyId = $autoBudget->transaction_currency_id;$spentAmount = $spent[$currencyId]['sum'] ?? '0';Log::debug(sprintf('Spent in previous budget period (%s-%s) is %s', $previousStart->format('Y-m-d'), $previousEnd->format('Y-m-d'), $spentAmount));@@ -212,7 +218,13 @@ class CreateAutoBudgetLimits implements ShouldQueue// if has one, calculate expenses and use that as a base.$repository = app(OperationsRepositoryInterface::class);$repository->setUser($autoBudget->budget->user);- $spent = $repository->sumExpenses($previousStart, $previousEnd, null, new Collection()->push($autoBudget->budget), $autoBudget->transactionCurrency);+ $spent = $repository->sumExpenses(+ $previousStart,+ $previousEnd,+ null,+ new Collection()->push($autoBudget->budget),+ $autoBudget->transactionCurrency+ );$currencyId = $autoBudget->transaction_currency_id;$spentAmount = $spent[$currencyId]['sum'] ?? '0';Log::debug(sprintf('Spent in previous budget period (%s-%s) is %s', $previousStart->format('Y-m-d'), $previousEnd->format('Y-m-d'), $spentAmount));diff --git a/app/Jobs/CreateRecurringTransactions.php b/app/Jobs/CreateRecurringTransactions.phpindex b5b1e354cc..49f1d25b8c 100644--- a/app/Jobs/CreateRecurringTransactions.php+++ b/app/Jobs/CreateRecurringTransactions.php@@ -280,7 +280,7 @@ class CreateRecurringTransactions implements ShouldQueuereturn null;}- if ($journalCount > 0 && $this->force) {+ if ($journalCount > 0) {Log::warning(sprintf('Already created %d groups for date %s but FORCED to continue.', $journalCount, $date->format('Y-m-d')));}diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.phpindex c50503ea52..1f23eac434 100644--- a/app/Providers/FireflyServiceProvider.php+++ b/app/Providers/FireflyServiceProvider.php@@ -60,9 +60,9 @@ use FireflyIII\Services\Password\Verifier;use FireflyIII\Services\Webhook\StandardWebhookSender;use FireflyIII\Services\Webhook\WebhookSenderInterface;use FireflyIII\Support\Amount;+use FireflyIII\Support\AppConfiguration;use FireflyIII\Support\Balance;use FireflyIII\Support\ExpandedForm;-use FireflyIII\Support\AppConfiguration;use FireflyIII\Support\Form\AccountForm;use FireflyIII\Support\Form\CurrencyForm;use FireflyIII\Support\Form\PiggyBankForm;diff --git a/app/Repositories/Currency/CurrencyRepository.php b/app/Repositories/Currency/CurrencyRepository.phpindex ffd15b930b..1b69e88f14 100644--- a/app/Repositories/Currency/CurrencyRepository.php+++ b/app/Repositories/Currency/CurrencyRepository.php@@ -442,9 +442,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf{Log::debug('Now in update()');// can be true, false, null- $enabled = $data['enabled'] ?? null;+ $enabled = $data['enabled'] ?? null;// can be true, false, but method only responds to "true".- $default = array_key_exists('default', $data) ? $data['default'] : false;+ $default = array_key_exists('default', $data) ? $data['default'] : false;// remove illegal combo's:if (false === $enabled && true === $default) {@@ -477,7 +477,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf}/** @var CurrencyUpdateService $service */- $service = app(CurrencyUpdateService::class);+ $service = app(CurrencyUpdateService::class);return $service->update($currency, $data);}diff --git a/app/Services/Internal/Update/JournalUpdateService.php b/app/Services/Internal/Update/JournalUpdateService.phpindex ffecbcf10c..c8a76660d9 100644--- a/app/Services/Internal/Update/JournalUpdateService.php+++ b/app/Services/Internal/Update/JournalUpdateService.php@@ -700,7 +700,7 @@ class JournalUpdateService// add foreign currency info to source and destination if possible.if (null !== $foreignCurrency && null !== $foreignAmount) {- $source->foreign_currency_id = $foreignCurrency->id;+ $source->foreign_currency_id = (int) $foreignCurrency->id;$source->foreign_amount = Steam::negative($foreignAmount);$source->save();@@ -713,13 +713,13 @@ class JournalUpdateServiceif ($isTransfer || $isBetween) {Log::debug('Switch amounts, store in amount and not foreign_amount');- $dest->transaction_currency_id = $foreignCurrency->id;+ $dest->transaction_currency_id = (int) $foreignCurrency->id;$dest->amount = Steam::positive($foreignAmount);$dest->foreign_amount = Steam::positive($source->amount);$dest->foreign_currency_id = $source->transaction_currency_id;}if (!$isTransfer && !$isBetween) {- $dest->foreign_currency_id = $foreignCurrency->id;+ $dest->foreign_currency_id = (int) $foreignCurrency->id;$dest->foreign_amount = Steam::positive($foreignAmount);}diff --git a/app/Support/Amount.php b/app/Support/Amount.phpindex 05a8ff4721..d610b61b4e 100644--- a/app/Support/Amount.php+++ b/app/Support/Amount.php@@ -60,11 +60,11 @@ class Amount// there are five possible positions for the "+" or "-" sign (if it is even used)// pos_a and pos_e could be the ( and ) symbol.- $posA = ''; // before everything- $posB = ''; // before currency symbol- $posC = ''; // after currency symbol- $posD = ''; // before amount- $posE = ''; // after everything+ $posA = ''; // before everything+ $posB = ''; // before currency symbol+ $posC = ''; // after currency symbol+ $posD = ''; // before amount+ $posE = ''; // after everything// format would be (currency before amount)// AB%sC_D%vE@@ -106,10 +106,10 @@ class Amount}if ($csPrecedes) {- return $posA . $posB . '%s' . $posC . $space . $posD . '%v' . $posE;+ return $posA.$posB.'%s'.$posC.$space.$posD.'%v'.$posE;}- return $posA . $posD . '%v' . $space . $posB . '%s' . $posC . $posE;+ return $posA.$posD.'%v'.$space.$posB.'%s'.$posC.$posE;}public function convertToPrimary(?User $user = null): bool@@ -120,7 +120,7 @@ class Amountif (null === $pref) {$res= true === Preferences::get('convert_to_primary', false)->data- && true === AppConfiguration::get('enable_exchange_rates', config('cer.enabled'))->data;+ && true === AppConfiguration::get('enable_exchange_rates', config('cer.enabled'))->data;$instance->setPreference('convert_to_primary_no_user', $res);return $res;@@ -128,12 +128,12 @@ class Amountreturn $pref;}- $key = sprintf('convert_to_primary_%d', $user->id);- $pref = $instance->getPreference($key);+ $key = sprintf('convert_to_primary_%d', $user->id);+ $pref = $instance->getPreference($key);if (null === $pref) {$res= true === Preferences::getForUser($user, 'convert_to_primary', false)->data- && true === AppConfiguration::get('enable_exchange_rates', config('cer.enabled'))->data;+ && true === AppConfiguration::get('enable_exchange_rates', config('cer.enabled'))->data;$instance->setPreference($key, $res);return $res;@@ -168,16 +168,16 @@ class Amount*/public function formatFlat(string $symbol, int $decimalPlaces, string $amount, ?bool $coloured = null): string{- $amount = Steam::anonymous() ? '0' : $amount;- $locale = Steam::getLocale();- $rounded = Steam::bcround($amount, $decimalPlaces);+ $amount = Steam::anonymous() ? '0' : $amount;+ $locale = Steam::getLocale();+ $rounded = Steam::bcround($amount, $decimalPlaces);$coloured ??= true;- $fmt = new NumberFormatter($locale, NumberFormatter::CURRENCY);+ $fmt = new NumberFormatter($locale, NumberFormatter::CURRENCY);$fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, $symbol);$fmt->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces);$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);- $result = (string)$fmt->format((float)$rounded); // intentional float+ $result = (string) $fmt->format((float) $rounded); // intentional floatif ($coloured) {if (1 === bccomp($rounded, '0')) {@@ -210,13 +210,13 @@ class Amount$amount = $journal[$field] ?? '0';// Log::debug(sprintf('Field is %s, amount is %s', $field, $amount));// fallback, the transaction has a foreign amount in $currency.- if ($convertToPrimary && null !== $journal['foreign_amount'] && $currency->id === (int)$journal['foreign_currency_id']) {+ if ($convertToPrimary && null !== $journal['foreign_amount'] && $currency->id === (int) $journal['foreign_currency_id']) {$amount = $journal['foreign_amount'];// Log::debug(sprintf('Overruled, amount is now %s', $amount));}- return (string)$amount;+ return (string) $amount;}/**@@ -226,9 +226,9 @@ class Amountpublic function getAmountFromJournalObject(TransactionJournal $journal): string{// Log::debug(sprintf('Get amount from journal #%d', $journal->id));- $convertToPrimary = $this->convertToPrimary();- $currency = $this->getPrimaryCurrency();- $field = $convertToPrimary && $currency->id !== $journal->transaction_currency_id ? 'native_amount' : 'amount';+ $convertToPrimary = $this->convertToPrimary();+ $currency = $this->getPrimaryCurrency();+ $field = $convertToPrimary && $currency->id !== $journal->transaction_currency_id ? 'native_amount' : 'amount';/** @var null|Transaction $sourceTransaction */$sourceTransaction = $journal->transactions()->where('amount', '<', 0)->first();@@ -236,11 +236,11 @@ class Amount// Log::debug('Return zero!');return '0';}- $amount = $sourceTransaction->{$field} ?? '0';+ $amount = $sourceTransaction->{$field} ?? '0';// Log::debug(sprintf('Amount is %s', $amount));- if ((int)$sourceTransaction->foreign_currency_id === $currency->id) {+ if ((int) $sourceTransaction->foreign_currency_id === $currency->id) {// use foreign amount instead!- $amount = (string)$sourceTransaction->foreign_amount; // hard coded to be foreign amount.+ $amount = (string) $sourceTransaction->foreign_amount; // hard coded to be foreign amount.// Log::debug(sprintf('Amount is now %s', $amount));}@@ -293,11 +293,12 @@ class Amountpublic function getPrimaryCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency{- $cache = new CacheProperties();+ $cache = new CacheProperties();$cache->addProperty('getPrimaryCurrencyByGroup');$cache->addProperty($userGroup->id);if ($cache->has()) {Log::debug(sprintf('getPrimaryCurrencyByUserGroup(#%d, "%s") = %s', $userGroup->id, $userGroup->title, $cache->get()->code));+return $cache->get();}@@ -325,7 +326,7 @@ class Amount$key = sprintf('transaction_currency_%s', $code);/** @var null|TransactionCurrency $pref */- $pref = $instance->getPreference($key);+ $pref = $instance->getPreference($key);if (null !== $pref) {return $pref;}@@ -352,7 +353,7 @@ class Amount$key = sprintf('transaction_currency_%d', $currencyId);/** @var null|TransactionCurrency $pref */- $pref = $instance->getPreference($key);+ $pref = $instance->getPreference($key);if (null !== $pref) {return $pref;}@@ -379,20 +380,20 @@ class Amountprivate function getLocaleInfo(): array{// get config from preference, not from translation:- $locale = Steam::getLocale();- $array = Steam::getLocaleArray($locale);+ $locale = Steam::getLocale();+ $array = Steam::getLocaleArray($locale);setlocale(LC_MONETARY, $array);- $info = localeconv();+ $info = localeconv();// correct variables- $info['n_cs_precedes'] = $this->getLocaleField($info, 'n_cs_precedes');- $info['p_cs_precedes'] = $this->getLocaleField($info, 'p_cs_precedes');+ $info['n_cs_precedes'] = $this->getLocaleField($info, 'n_cs_precedes');+ $info['p_cs_precedes'] = $this->getLocaleField($info, 'p_cs_precedes');- $info['n_sep_by_space'] = $this->getLocaleField($info, 'n_sep_by_space');- $info['p_sep_by_space'] = $this->getLocaleField($info, 'p_sep_by_space');+ $info['n_sep_by_space'] = $this->getLocaleField($info, 'n_sep_by_space');+ $info['p_sep_by_space'] = $this->getLocaleField($info, 'p_sep_by_space');- $fmt = new NumberFormatter($locale, NumberFormatter::CURRENCY);+ $fmt = new NumberFormatter($locale, NumberFormatter::CURRENCY);$info['mon_decimal_point'] = $fmt->getSymbol(NumberFormatter::MONETARY_SEPARATOR_SYMBOL);$info['mon_thousands_sep'] = $fmt->getSymbol(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL);diff --git a/app/Support/Http/Controllers/AugumentData.php b/app/Support/Http/Controllers/AugumentData.phpindex a3a940b1ba..a507156873 100644--- a/app/Support/Http/Controllers/AugumentData.php+++ b/app/Support/Http/Controllers/AugumentData.php@@ -222,7 +222,14 @@ trait AugumentData$currentEnd->addMonth();}// primary currency amount.- $expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $entry->transactionCurrency, $this->convertToPrimary);+ $expenses = $opsRepository->sumExpenses(+ $currentStart,+ $currentEnd,+ null,+ $budgetCollection,+ $entry->transactionCurrency,+ $this->convertToPrimary+ );$spent = $expenses[$currency->id]['sum'] ?? '0';$entry->pc_spent = $spent;diff --git a/app/Support/JsonApi/Enrichments/RecurringEnrichment.php b/app/Support/JsonApi/Enrichments/RecurringEnrichment.phpindex d0c09bf027..2428353cb0 100644--- a/app/Support/JsonApi/Enrichments/RecurringEnrichment.php+++ b/app/Support/JsonApi/Enrichments/RecurringEnrichment.php@@ -354,7 +354,11 @@ class RecurringEnrichment implements EnrichmentInterface/** @var RecurrenceRepetition $repetition */foreach ($set as $repetition) {- $recurrence = $this->collection->filter(static fn (Recurrence $item): bool => (int) $item->id === (int) $repetition->recurrence_id)->first();+ $recurrence = $this->collection->filter(+ static fn (Recurrence $item): bool => (int) $item->id === (int) $repetition->recurrence_id+ )+ ->first()+ ;$fromDate = clone ($recurrence->latest_date ?? $recurrence->first_date);$recurrenceId = (int) $repetition->recurrence_id;$repId = (int) $repetition->id;diff --git a/config/firefly.php b/config/firefly.phpindex 942f5a074b..dae183ac76 100644--- a/config/firefly.php+++ b/config/firefly.php@@ -78,8 +78,8 @@ return ['running_balance_column' => (bool)env_default_when_empty(env('USE_RUNNING_BALANCE'), true), // this is only the default value, is not used.// see cer.php for exchange rates feature flag.],-'version' => 'develop/2026-06-05',-'build_time' => 1780631165,+ 'version' => 'develop/2026-06-05',+ 'build_time' => 1780631165,'api_version' => '2.1.0', // field is no longer used.'db_version' => 28, // field is no longer used.