Final nestor and phpstan fixes.

This commit is contained in:
James Cole
2025-09-07 17:42:16 +02:00
parent f5c202543c
commit 81cd89d66f
47 changed files with 59 additions and 128 deletions

View File

@@ -60,7 +60,7 @@ class AccountEnrichment implements EnrichmentInterface
private array $currencies = [];
private array $locations = [];
private array $meta = [];
private TransactionCurrency $primaryCurrency;
private readonly TransactionCurrency $primaryCurrency;
private array $notes = [];
private array $openingBalances = [];
private User $user;
@@ -69,7 +69,7 @@ class AccountEnrichment implements EnrichmentInterface
private ?Carbon $date = null;
private ?Carbon $start = null;
private ?Carbon $end = null;
private bool $convertToPrimary;
private readonly bool $convertToPrimary;
private array $balances = [];
private array $startBalances = [];
private array $endBalances = [];
@@ -365,7 +365,7 @@ class AccountEnrichment implements EnrichmentInterface
private function collectBalances(): void
{
$this->balances = Steam::accountsBalancesOptimized($this->collection, $this->getDate(), $this->primaryCurrency, $this->convertToPrimary);
if (null !== $this->start && null !== $this->end) {
if ($this->start instanceof Carbon && $this->end instanceof Carbon) {
$this->startBalances = Steam::accountsBalancesOptimized($this->collection, $this->start, $this->primaryCurrency, $this->convertToPrimary);
$this->endBalances = Steam::accountsBalancesOptimized($this->collection, $this->end, $this->primaryCurrency, $this->convertToPrimary);
}
@@ -395,7 +395,7 @@ class AccountEnrichment implements EnrichmentInterface
public function setDate(?Carbon $date): void
{
if (null !== $date) {
if ($date instanceof Carbon) {
$date->endOfDay();
Log::debug(sprintf('Date is now %s', $date->toW3cString()));
}
@@ -404,7 +404,7 @@ class AccountEnrichment implements EnrichmentInterface
public function getDate(): Carbon
{
if (null === $this->date) {
if (!$this->date instanceof Carbon) {
return now();
}
@@ -423,7 +423,7 @@ class AccountEnrichment implements EnrichmentInterface
private function getBalanceDifference(int $id, TransactionCurrency $currency): ?string
{
if (null === $this->start || null === $this->end) {
if (!$this->start instanceof Carbon || !$this->end instanceof Carbon) {
return null;
}
$startBalance = $this->startBalances[$id] ?? [];
@@ -458,9 +458,7 @@ class AccountEnrichment implements EnrichmentInterface
case 'current_balance':
case 'pc_current_balance':
$this->collection = $this->collection->sortBy(static function (Account $account) use ($parameter) {
return $account->meta['balances'][$parameter[0]] ?? '0';
}, SORT_NUMERIC, 'desc' === $parameter[1]);
$this->collection = $this->collection->sortBy(static fn(Account $account) => $account->meta['balances'][$parameter[0]] ?? '0', SORT_NUMERIC, 'desc' === $parameter[1]);
break;
}

View File

@@ -42,7 +42,7 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
{
private User $user; // @phpstan-ignore-line
private UserGroup $userGroup; // @phpstan-ignore-line
private bool $convertToPrimary;
private readonly bool $convertToPrimary;
private array $ids = [];
private array $currencyIds = [];
private array $currencies = [];

View File

@@ -161,7 +161,7 @@ class BudgetEnrichment implements EnrichmentInterface
private function collectExpenses(): 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

@@ -53,7 +53,7 @@ class BudgetLimitEnrichment implements EnrichmentInterface
private array $currencyIds = [];
private array $currencies = [];
private bool $convertToPrimary = true;
private TransactionCurrency $primaryCurrency;
private readonly TransactionCurrency $primaryCurrency;
public function __construct()
{
@@ -181,27 +181,21 @@ class BudgetLimitEnrichment implements EnrichmentInterface
private function stringifyIds(): void
{
$this->expenses = array_map(function ($first) {
return array_map(function ($second) {
$second['currency_id'] = (string)($second['currency_id'] ?? 0);
$this->expenses = array_map(fn($first) => array_map(function ($second) {
$second['currency_id'] = (string)($second['currency_id'] ?? 0);
return $second;
}, $first);
}, $this->expenses);
return $second;
}, $first), $this->expenses);
$this->pcExpenses = array_map(function ($first) {
return array_map(function ($second) {
$second['currency_id'] = (string)($second['currency_id'] ?? 0);
$this->pcExpenses = array_map(fn($first) => array_map(function ($second) {
$second['currency_id'] = (string)($second['currency_id'] ?? 0);
return $second;
}, $first);
}, $this->expenses);
return $second;
}, $first), $this->expenses);
}
private function filterToBudget(array $expenses, int $budget): array
{
return array_filter($expenses, function (array $item) use ($budget) {
return (int)$item['budget_id'] === $budget;
});
return array_filter($expenses, fn(array $item) => (int)$item['budget_id'] === $budget);
}
}

View File

@@ -53,7 +53,7 @@ class PiggyBankEnrichment implements EnrichmentInterface
// private array $accountCurrencies = [];
private array $notes = [];
private array $mappedObjects = [];
private TransactionCurrency $primaryCurrency;
private readonly TransactionCurrency $primaryCurrency;
private array $amounts = [];
private array $accounts = [];
private array $objectGroups = [];
@@ -271,7 +271,7 @@ class PiggyBankEnrichment implements EnrichmentInterface
*/
private function getSuggestedMonthlyAmount(?Carbon $startDate, ?Carbon $targetDate, ?string $targetAmount, string $currentAmount): string
{
if (null === $targetAmount || null === $targetDate || null === $startDate) {
if (null === $targetAmount || !$targetDate instanceof Carbon || !$startDate instanceof Carbon) {
return '0';
}
$savePerMonth = '0';

View File

@@ -27,7 +27,6 @@ namespace FireflyIII\Support\JsonApi\Enrichments;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\UserGroup;
use FireflyIII\Support\Facades\Amount;

View File

@@ -49,7 +49,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
private User $user;
private UserGroup $userGroup; // @phpstan-ignore-line
private Collection $collection;
private bool $convertToPrimary;
private readonly bool $convertToPrimary;
private ?Carbon $start = null;
private ?Carbon $end = null;
private array $subscriptionIds = [];
@@ -58,7 +58,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
private array $paidDates = [];
private array $notes = [];
private array $payDates = [];
private TransactionCurrency $primaryCurrency;
private readonly TransactionCurrency $primaryCurrency;
private BillDateCalculator $calculator;
public function __construct()
@@ -210,7 +210,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
{
$this->paidDates = [];
Log::debug('Now in collectPaidDates for bills');
if (null === $this->start || null === $this->end) {
if (!$this->start instanceof Carbon || !$this->end instanceof Carbon) {
Log::debug('Parameters are NULL, set empty array');
return;
@@ -274,9 +274,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
// At this point the "next match" is exactly after the last time the bill was paid.
$result = [];
$filtered = $set->filter(function (TransactionJournal $journal) use ($subscription) {
return (int)$journal->bill_id === (int)$subscription->id;
});
$filtered = $set->filter(fn(TransactionJournal $journal) => (int)$journal->bill_id === (int)$subscription->id);
foreach ($filtered as $entry) {
$array = [
'transaction_group_id' => (string)$entry->transaction_group_id,
@@ -346,9 +344,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
*/
protected function lastPaidDate(Bill $subscription, Collection $dates, Carbon $default): Carbon
{
$filtered = $dates->filter(function (TransactionJournal $journal) use ($subscription) {
return (int)$journal->bill_id === (int)$subscription->id;
});
$filtered = $dates->filter(fn(TransactionJournal $journal) => (int)$journal->bill_id === (int)$subscription->id);
Log::debug(sprintf('Filtered down from %d to %d entries for bill #%d.', $dates->count(), $filtered->count(), $subscription->id));
if (0 === $filtered->count()) {
return $default;
@@ -392,7 +388,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
private function collectPayDates(): void
{
if (null === $this->start || null === $this->end) {
if (!$this->start instanceof Carbon || !$this->end instanceof Carbon) {
Log::debug('Parameters are NULL, set empty array');
return;
@@ -440,8 +436,8 @@ class SubscriptionEnrichment implements EnrichmentInterface
// nullify again when it's outside the current view range.
if (
(null !== $this->start && $nemDate->lt($this->start))
|| (null !== $this->end && $nemDate->gt($this->end))
($this->start instanceof Carbon && $nemDate->lt($this->start))
|| ($this->end instanceof Carbon && $nemDate->gt($this->end))
) {
$nem = null;
$nemDate = null;
@@ -454,7 +450,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
private function getNextExpectedMatchDiff(?Carbon $nem, array $payDates): string
{
if (null === $nem) {
if (!$nem instanceof Carbon) {
return trans('firefly.not_expected_period');
}
$nemDiff = trans('firefly.not_expected_period');