Fix some rector code.

This commit is contained in:
James Cole
2025-09-27 05:57:58 +02:00
parent 0f0a28c3d9
commit ac0113e445
21 changed files with 53 additions and 49 deletions

View File

@@ -38,7 +38,7 @@ class Timer
public static function getInstance(): self
{
if (null === self::$instance) {
if (!self::$instance instanceof \FireflyIII\Support\Debug\Timer) {
self::$instance = new self();
}

View File

@@ -724,7 +724,7 @@ trait PeriodOverview
protected function saveGroupedAsStatistics(Model $model, Carbon $start, Carbon $end, string $type, array $array): void
{
unset($array['count']);
Log::debug(sprintf('saveGroupedAsStatistics(%s #%d, %s, %s, "%s", array(%d))', get_class($model), $model->id, $start->format('Y-m-d'), $end->format('Y-m-d'), $type, count($array)));
Log::debug(sprintf('saveGroupedAsStatistics(%s #%d, %s, %s, "%s", array(%d))', $model::class, $model->id, $start->format('Y-m-d'), $end->format('Y-m-d'), $type, count($array)));
foreach ($array as $entry) {
$this->periodStatisticRepo->saveStatistic($model, $entry['currency_id'], $start, $end, $type, $entry['count'], $entry['amount']);
}
@@ -899,7 +899,7 @@ trait PeriodOverview
];
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $amount);
$return[$currencyId]['amount'] = bcadd((string) $return[$currencyId]['amount'], $amount);
++$return[$currencyId]['count'];
++$return['count'];
}

View File

@@ -135,7 +135,7 @@ class CategoryEnrichment implements EnrichmentInterface
private function collectTransactions(): void
{
if (null !== $this->start && null !== $this->end) {
if ($this->start instanceof Carbon && $this->end instanceof Carbon) {
/** @var OperationsRepositoryInterface $opsRepository */
$opsRepository = app(OperationsRepositoryInterface::class);
$opsRepository->setUser($this->user);

View File

@@ -142,9 +142,9 @@ class PiggyBankEnrichment implements EnrichmentInterface
'current_amount' => Steam::bcround($row['current_amount'], $currency->decimal_places),
'pc_current_amount' => Steam::bcround($row['pc_current_amount'], $this->primaryCurrency->decimal_places),
];
$meta['current_amount'] = bcadd($meta['current_amount'], $row['current_amount']);
$meta['current_amount'] = bcadd($meta['current_amount'], (string) $row['current_amount']);
// only add pc_current_amount when the pc_current_amount is set
$meta['pc_current_amount'] = null === $row['pc_current_amount'] ? null : bcadd($meta['pc_current_amount'], $row['pc_current_amount']);
$meta['pc_current_amount'] = null === $row['pc_current_amount'] ? null : bcadd((string) $meta['pc_current_amount'], (string) $row['pc_current_amount']);
}
$meta['current_amount'] = Steam::bcround($meta['current_amount'], $currency->decimal_places);
// only round this number when pc_current_amount is set.
@@ -152,8 +152,8 @@ class PiggyBankEnrichment implements EnrichmentInterface
// calculate left to save, only when there is a target amount.
if (null !== $targetAmount) {
$meta['left_to_save'] = bcsub($meta['target_amount'], $meta['current_amount']);
$meta['pc_left_to_save'] = null === $meta['pc_target_amount'] ? null : bcsub($meta['pc_target_amount'], $meta['pc_current_amount']);
$meta['left_to_save'] = bcsub((string) $meta['target_amount'], (string) $meta['current_amount']);
$meta['pc_left_to_save'] = null === $meta['pc_target_amount'] ? null : bcsub((string) $meta['pc_target_amount'], (string) $meta['pc_current_amount']);
}
// get suggested per month.
@@ -199,7 +199,7 @@ class PiggyBankEnrichment implements EnrichmentInterface
'pc_current_amount' => '0',
];
}
$this->amounts[$id][$accountId]['current_amount'] = bcadd($this->amounts[$id][$accountId]['current_amount'], (string)$item->current_amount);
$this->amounts[$id][$accountId]['current_amount'] = bcadd((string) $this->amounts[$id][$accountId]['current_amount'], (string)$item->current_amount);
if (null !== $this->amounts[$id][$accountId]['pc_current_amount'] && null !== $item->native_current_amount) {
$this->amounts[$id][$accountId]['pc_current_amount'] = bcadd($this->amounts[$id][$accountId]['pc_current_amount'], (string)$item->native_current_amount);
}

View File

@@ -197,7 +197,7 @@ trait RecalculatesAvailableBudgetsTrait
// if not exists:
$currentPeriod = Period::make($current, $currentEnd, precision: Precision::DAY(), boundaries: Boundaries::EXCLUDE_NONE());
$daily = $this->getDailyAmount($budgetLimit);
$amount = bcmul($daily, (string)$currentPeriod->length(), 12);
$amount = bcmul((string) $daily, (string)$currentPeriod->length(), 12);
// no need to calculate if period is equal.
if ($currentPeriod->equals($limitPeriod)) {

View File

@@ -193,7 +193,7 @@ class TransactionSummarizer
];
// add the data from the $field to the array.
$array[$key]['sum'] = bcadd($array[$key]['sum'], Steam::{$method}((string)($journal[$field] ?? '0'))); // @phpstan-ignore-line
$array[$key]['sum'] = bcadd($array[$key]['sum'], (string) Steam::{$method}((string)($journal[$field] ?? '0'))); // @phpstan-ignore-line
Log::debug(sprintf('Field for transaction #%d is "%s" (%s). Sum: %s', $journal['transaction_group_id'], $currencyCode, $field, $array[$key]['sum']));
// also do foreign amount, but only when convertToPrimary is false (otherwise we have it already)
@@ -211,7 +211,7 @@ class TransactionSummarizer
'currency_code' => $journal['foreign_currency_code'],
'currency_decimal_places' => $journal['foreign_currency_decimal_places'],
];
$array[$key]['sum'] = bcadd($array[$key]['sum'], Steam::{$method}((string)$journal['foreign_amount'])); // @phpstan-ignore-line
$array[$key]['sum'] = bcadd($array[$key]['sum'], (string) Steam::{$method}((string)$journal['foreign_amount'])); // @phpstan-ignore-line
}
}

View File

@@ -38,7 +38,7 @@ class PreferencesSingleton
public static function getInstance(): self
{
if (null === self::$instance) {
if (!self::$instance instanceof PreferencesSingleton) {
self::$instance = new self();
}

View File

@@ -756,7 +756,7 @@ class Steam
$current = $converter->convert($currency, $primary, $date, $amount);
Log::debug(sprintf('Convert %s %s to %s %s', $currency->code, $amount, $primary->code, $current));
}
$total = bcadd($current, $total);
$total = bcadd((string) $current, $total);
}
return $total;