[chore] fix phpstan errors.

This commit is contained in:
James Cole
2025-01-19 19:07:19 +01:00
parent 6e836aceec
commit 053b46ae63
52 changed files with 68 additions and 108 deletions

View File

@@ -55,7 +55,7 @@ class Amount
public function getAmountFromJournal(array $journal): string
{
$convertToNative = $this->convertToNative();
$currency = $this->getDefaultCurrency();
$currency = $this->getNativeCurrency();
$field = $convertToNative && $currency->id !== $journal['currency_id'] ? 'native_amount' : 'amount';
$amount = $journal[$field] ?? '0';
// Log::debug(sprintf('Field is %s, amount is %s', $field, $amount));
@@ -86,7 +86,7 @@ class Amount
public function getAmountFromJournalObject(TransactionJournal $journal): string
{
$convertToNative = $this->convertToNative();
$currency = $this->getDefaultCurrency();
$currency = $this->getNativeCurrency();
$field = $convertToNative && $currency->id !== $journal->transaction_currency_id ? 'native_amount' : 'amount';
/** @var null|Transaction $sourceTransaction */
@@ -193,7 +193,7 @@ class Amount
return $cache->get();
}
/** @var null|TransactionCurrency $default */
/** @var null|TransactionCurrency $native */
$native = $userGroup->currencies()->where('group_default', true)->first();
if (null === $native) {
$native = $this->getSystemCurrency();

View File

@@ -736,7 +736,7 @@ class ExportDataGenerator
$metaFields = config('firefly.journal_meta_fields');
$header = array_merge($header, $metaFields);
$default = Amount::getDefaultCurrency();
$default = Amount::getNativeCurrency();
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user);

View File

@@ -60,7 +60,7 @@ class CurrencyForm
$classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value);
$options['step'] = 'any';
$defaultCurrency = $options['currency'] ?? app('amount')->getDefaultCurrency();
$defaultCurrency = $options['currency'] ?? app('amount')->getNativeCurrency();
/** @var Collection $currencies */
$currencies = app('amount')->getCurrencies();
@@ -128,7 +128,7 @@ class CurrencyForm
$classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value);
$options['step'] = 'any';
$defaultCurrency = $options['currency'] ?? app('amount')->getDefaultCurrency();
$defaultCurrency = $options['currency'] ?? app('amount')->getNativeCurrency();
/** @var Collection $currencies */
$currencies = app('amount')->getAllCurrencies();

View File

@@ -66,7 +66,7 @@ trait ChartGeneration
/** @var AccountRepositoryInterface $accountRepos */
$accountRepos = app(AccountRepositoryInterface::class);
$default = app('amount')->getDefaultCurrency();
$default = app('amount')->getNativeCurrency();
$chartData = [];
/** @var Account $account */

View File

@@ -82,7 +82,7 @@ class AccountEnrichment implements EnrichmentInterface
Log::debug(sprintf('Now doing account enrichment for %d account(s)', $collection->count()));
// prep local fields
$this->collection = $collection;
$this->default = app('amount')->getDefaultCurrency();
$this->default = app('amount')->getNativeCurrency();
$this->currencies = [];
$this->balances = [];
$this->objectGroups = [];

View File

@@ -155,7 +155,7 @@ class QueryParser implements QueryParserInterface
$fieldName = $tokenUnderConstruction;
$tokenUnderConstruction = '';
}
if ('' === $tokenUnderConstruction) {
if ('' === $tokenUnderConstruction) { // @phpstan-ignore-line
// In any other location, it's just a normal character
$tokenUnderConstruction .= $char;
}

View File

@@ -407,7 +407,7 @@ class Steam
return [];
}
$defaultCurrency = app('amount')->getDefaultCurrency();
$defaultCurrency = app('amount')->getNativeCurrency();
if ($convertToNative) {
if ($defaultCurrency->id === $currency?->id) {
Log::debug(sprintf('Unset "native_balance" and "%s" for account #%d', $defaultCurrency->code, $account->id));

View File

@@ -48,7 +48,7 @@ class AmountFormat extends AbstractExtension
return new TwigFilter(
'formatAmount',
static function (string $string): string {
$currency = app('amount')->getDefaultCurrency();
$currency = app('amount')->getNativeCurrency();
return app('amount')->formatAnything($currency, $string, true);
},
@@ -61,7 +61,7 @@ class AmountFormat extends AbstractExtension
return new TwigFilter(
'formatAmountPlain',
static function (string $string): string {
$currency = app('amount')->getDefaultCurrency();
$currency = app('amount')->getNativeCurrency();
return app('amount')->formatAnything($currency, $string, false);
},
@@ -93,7 +93,7 @@ class AmountFormat extends AbstractExtension
/** @var AccountRepositoryInterface $accountRepos */
$accountRepos = app(AccountRepositoryInterface::class);
$currency = $accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$currency = $accountRepos->getAccountCurrency($account) ?? app('amount')->getNativeCurrency();
return app('amount')->formatAnything($currency, $amount, $coloured);
},

View File

@@ -69,7 +69,7 @@ class General extends AbstractExtension
$date = session('end', today(config('app.timezone'))->endOfMonth());
$info = Steam::finalAccountBalance($account, $date);
$currency = Steam::getAccountCurrency($account);
$default = Amount::getDefaultCurrency();
$default = Amount::getNativeCurrency();
$convertToNative = Amount::convertToNative();
$useNative = $convertToNative && $default->id !== $currency->id;
$strings = [];