Fix phpstan issues.

This commit is contained in:
James Cole
2025-09-07 07:43:04 +02:00
parent 296a64e284
commit 602df95f3c
12 changed files with 109 additions and 113 deletions

View File

@@ -440,7 +440,7 @@ class AccountEnrichment implements EnrichmentInterface
private function sortData(): void private function sortData(): void
{ {
$dbParams = config('firefly.allowed_db_sort_parameters.Account', []); $dbParams = config('firefly.allowed_db_sort_parameters.Account', []);
/** @var array<int,<string,string> $parameter */ /** @var array $parameter */
foreach ($this->sort as $parameter) { foreach ($this->sort as $parameter) {
if (in_array($parameter[0], $dbParams, true)) { if (in_array($parameter[0], $dbParams, true)) {
continue; continue;

View File

@@ -40,9 +40,8 @@ use Override;
class AvailableBudgetEnrichment implements EnrichmentInterface class AvailableBudgetEnrichment implements EnrichmentInterface
{ {
private User $user; private User $user; // @phpstan-ignore-line
private UserGroup $userGroup; private UserGroup $userGroup; // @phpstan-ignore-line
private TransactionCurrency $primaryCurrency;
private bool $convertToPrimary; private bool $convertToPrimary;
private array $ids = []; private array $ids = [];
private array $currencyIds = []; private array $currencyIds = [];
@@ -57,12 +56,9 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
private readonly BudgetRepositoryInterface $repository; private readonly BudgetRepositoryInterface $repository;
private ?Carbon $start = null;
private ?Carbon $end = null;
public function __construct() public function __construct()
{ {
$this->primaryCurrency = Amount::getPrimaryCurrency(); //$this->primaryCurrency = Amount::getPrimaryCurrency();
$this->convertToPrimary = Amount::convertToPrimary(); $this->convertToPrimary = Amount::convertToPrimary();
$this->noBudgetRepository = app(NoBudgetRepositoryInterface::class); $this->noBudgetRepository = app(NoBudgetRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class);
@@ -124,8 +120,8 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
$start = $this->collection->min('start_date') ?? Carbon::now()->startOfMonth(); $start = $this->collection->min('start_date') ?? Carbon::now()->startOfMonth();
$end = $this->collection->max('end_date') ?? Carbon::now()->endOfMonth(); $end = $this->collection->max('end_date') ?? Carbon::now()->endOfMonth();
$allActive = $this->repository->getActiveBudgets(); $allActive = $this->repository->getActiveBudgets();
$spentInBudgets = $this->opsRepository->collectExpenses($start, $end, null, $allActive, null); $spentInBudgets = $this->opsRepository->collectExpenses($start, $end, null, $allActive);
$spentOutsideBudgets = $this->noBudgetRepository->collectExpenses($start, $end, null, null, null); $spentOutsideBudgets = $this->noBudgetRepository->collectExpenses($start, $end);
foreach ($this->collection as $availableBudget) { foreach ($this->collection as $availableBudget) {
$id = (int)$availableBudget->id; $id = (int)$availableBudget->id;
$currencyId = $this->currencyIds[$id]; $currencyId = $this->currencyIds[$id];

View File

@@ -43,8 +43,6 @@ use Illuminate\Support\Facades\Log;
class BudgetEnrichment implements EnrichmentInterface class BudgetEnrichment implements EnrichmentInterface
{ {
private Collection $collection; private Collection $collection;
private bool $convertToPrimary;
private TransactionCurrency $primaryCurrency;
private User $user; private User $user;
private UserGroup $userGroup; private UserGroup $userGroup;
private array $ids = []; private array $ids = [];
@@ -60,8 +58,6 @@ class BudgetEnrichment implements EnrichmentInterface
public function __construct() public function __construct()
{ {
$this->convertToPrimary = Amount::convertToPrimary();
$this->primaryCurrency = Amount::getPrimaryCurrency();
} }
public function enrich(Collection $collection): Collection public function enrich(Collection $collection): Collection

View File

@@ -41,7 +41,7 @@ use Illuminate\Support\Facades\Log;
class BudgetLimitEnrichment implements EnrichmentInterface class BudgetLimitEnrichment implements EnrichmentInterface
{ {
private User $user; private User $user;
private UserGroup $userGroup; private UserGroup $userGroup; // @phpstan-ignore-line
private Collection $collection; private Collection $collection;
private array $ids = []; private array $ids = [];
private array $notes = []; private array $notes = [];

View File

@@ -43,8 +43,8 @@ use Illuminate\Support\Facades\Log;
class PiggyBankEnrichment implements EnrichmentInterface class PiggyBankEnrichment implements EnrichmentInterface
{ {
private User $user; private User $user; // @phpstan-ignore-line
private UserGroup $userGroup; private UserGroup $userGroup; // @phpstan-ignore-line
private Collection $collection; private Collection $collection;
private array $ids = []; private array $ids = [];
private array $currencyIds = []; private array $currencyIds = [];
@@ -55,6 +55,8 @@ class PiggyBankEnrichment implements EnrichmentInterface
private array $mappedObjects = []; private array $mappedObjects = [];
private TransactionCurrency $primaryCurrency; private TransactionCurrency $primaryCurrency;
private array $amounts = []; private array $amounts = [];
private array $accounts= [];
private array $objectGroups= [];
public function __construct() public function __construct()
{ {

View File

@@ -39,8 +39,8 @@ use Illuminate\Support\Facades\Log;
class PiggyBankEventEnrichment implements EnrichmentInterface class PiggyBankEventEnrichment implements EnrichmentInterface
{ {
private User $user; private User $user; // @phpstan-ignore-line
private UserGroup $userGroup; private UserGroup $userGroup; // @phpstan-ignore-line
private Collection $collection; private Collection $collection;
private array $ids = []; private array $ids = [];
private array $journalIds = []; private array $journalIds = [];

View File

@@ -57,7 +57,7 @@ class RecurringEnrichment implements EnrichmentInterface
{ {
private Collection $collection; private Collection $collection;
private array $ids = []; private array $ids = [];
private array $transactionTypeIds = []; // private array $transactionTypeIds = [];
// private array $transactionTypes = []; // private array $transactionTypes = [];
private array $notes = []; private array $notes = [];
private array $repetitions = []; private array $repetitions = [];
@@ -123,9 +123,9 @@ class RecurringEnrichment implements EnrichmentInterface
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
foreach ($this->collection as $recurrence) { foreach ($this->collection as $recurrence) {
$id = (int)$recurrence->id; $id = (int)$recurrence->id;
$typeId = (int)$recurrence->transaction_type_id; // $typeId = (int)$recurrence->transaction_type_id;
$this->ids[] = $id; $this->ids[] = $id;
$this->transactionTypeIds[$id] = $typeId; //$this->transactionTypeIds[$id] = $typeId;
} }
$this->ids = array_unique($this->ids); $this->ids = array_unique($this->ids);
@@ -410,7 +410,7 @@ class RecurringEnrichment implements EnrichmentInterface
// this should refer to another array, were rtIds can be used to find the recurrence. // this should refer to another array, were rtIds can be used to find the recurrence.
$recurrenceId = $this->recurrenceIds[$transactionId] ?? 0; $recurrenceId = $this->recurrenceIds[$transactionId] ?? 0;
$name = (string)$entry->name ?? ''; $name = (string)($entry->name ?? '');
if (0 === $recurrenceId) { if (0 === $recurrenceId) {
Log::error(sprintf('Could not find recurrence ID for recurrence transaction ID %d', $transactionId)); Log::error(sprintf('Could not find recurrence ID for recurrence transaction ID %d', $transactionId));

View File

@@ -27,6 +27,8 @@ namespace FireflyIII\Support\JsonApi\Enrichments;
use Carbon\Carbon; use Carbon\Carbon;
use Carbon\CarbonInterface; use Carbon\CarbonInterface;
use Carbon\Exceptions\InvalidFormatException;
use Carbon\Exceptions\ParseErrorException;
use FireflyIII\Models\Bill; use FireflyIII\Models\Bill;
use FireflyIII\Models\Note; use FireflyIII\Models\Note;
use FireflyIII\Models\ObjectGroup; use FireflyIII\Models\ObjectGroup;
@@ -46,7 +48,7 @@ use Illuminate\Support\Facades\Log;
class SubscriptionEnrichment implements EnrichmentInterface class SubscriptionEnrichment implements EnrichmentInterface
{ {
private User $user; private User $user;
private UserGroup $userGroup; private UserGroup $userGroup; // @phpstan-ignore-line
private Collection $collection; private Collection $collection;
private bool $convertToPrimary; private bool $convertToPrimary;
private ?Carbon $start = null; private ?Carbon $start = null;
@@ -155,8 +157,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
$notes = Note::query()->whereIn('noteable_id', $this->subscriptionIds) $notes = Note::query()->whereIn('noteable_id', $this->subscriptionIds)
->whereNotNull('notes.text') ->whereNotNull('notes.text')
->where('notes.text', '!=', '') ->where('notes.text', '!=', '')
->where('noteable_type', Bill::class)->get(['notes.noteable_id', 'notes.text'])->toArray() ->where('noteable_type', Bill::class)->get(['notes.noteable_id', 'notes.text'])->toArray();
;
foreach ($notes as $note) { foreach ($notes as $note) {
$this->notes[(int)$note['noteable_id']] = (string)$note['text']; $this->notes[(int)$note['noteable_id']] = (string)$note['text'];
} }
@@ -188,8 +189,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
$set = DB::table('object_groupables') $set = DB::table('object_groupables')
->whereIn('object_groupable_id', $this->subscriptionIds) ->whereIn('object_groupable_id', $this->subscriptionIds)
->where('object_groupable_type', Bill::class) ->where('object_groupable_type', Bill::class)
->get(['object_groupable_id', 'object_group_id']) ->get(['object_groupable_id', 'object_group_id']);
;
$ids = array_unique($set->pluck('object_group_id')->toArray()); $ids = array_unique($set->pluck('object_group_id')->toArray());
@@ -257,8 +257,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
'transactions.amount', 'transactions.amount',
'transactions.foreign_amount', 'transactions.foreign_amount',
] ]
) );
;
Log::debug(sprintf('Count %d entries in set', $set->count())); Log::debug(sprintf('Count %d entries in set', $set->count()));
// for each bill, do a loop. // for each bill, do a loop.
@@ -319,6 +318,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
// convert to primary, but foreign is NOT already primary. // convert to primary, but foreign is NOT already primary.
if ($this->convertToPrimary && null !== $entry->foreign_currency_id && (int)$entry->foreign_currency_id !== $this->primaryCurrency->id) { if ($this->convertToPrimary && null !== $entry->foreign_currency_id && (int)$entry->foreign_currency_id !== $this->primaryCurrency->id) {
// TODO this is very database intensive. // TODO this is very database intensive.
/** @var TransactionCurrency $foreignCurrency */
$foreignCurrency = TransactionCurrency::find($entry->foreign_currency_id); $foreignCurrency = TransactionCurrency::find($entry->foreign_currency_id);
$array['pc_foreign_amount'] = $converter->convert($foreignCurrency, $this->primaryCurrency, $entry->date, $entry->amount); $array['pc_foreign_amount'] = $converter->convert($foreignCurrency, $this->primaryCurrency, $entry->date, $entry->amount);
} }
@@ -399,7 +399,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
/** @var Bill $subscription */ /** @var Bill $subscription */
foreach ($this->collection as $subscription) { foreach ($this->collection as $subscription) {
$id = (int)$subscription->id; $id = (int)$subscription->id;
$lastPaidDate = $this->getLastPaidDate($paidDates[$id] ?? []); $lastPaidDate = $this->getLastPaidDate($this->paidDates[$id] ?? []);
$payDates = $this->calculator->getPayDates($this->start, $this->end, $subscription->date, $subscription->repeat_freq, $subscription->skip, $lastPaidDate); $payDates = $this->calculator->getPayDates($this->start, $this->end, $subscription->date, $subscription->repeat_freq, $subscription->skip, $lastPaidDate);
$payDatesFormatted = []; $payDatesFormatted = [];
foreach ($payDates as $string) { foreach ($payDates as $string) {
@@ -429,8 +429,9 @@ class SubscriptionEnrichment implements EnrichmentInterface
$firstPayDate = $payDates[0] ?? null; $firstPayDate = $payDates[0] ?? null;
if (null !== $firstPayDate) { if (null !== $firstPayDate) {
try {
$nemDate = Carbon::parse($firstPayDate, config('app.timezone')); $nemDate = Carbon::parse($firstPayDate, config('app.timezone'));
if (!$nemDate instanceof Carbon) { } catch (InvalidFormatException) {
$nemDate = today(config('app.timezone')); $nemDate = today(config('app.timezone'));
} }
$nem = $nemDate; $nem = $nemDate;
@@ -462,8 +463,9 @@ class SubscriptionEnrichment implements EnrichmentInterface
$current = $payDates[0] ?? null; $current = $payDates[0] ?? null;
if (null !== $current && !$nem->isToday()) { if (null !== $current && !$nem->isToday()) {
try {
$temp2 = Carbon::parse($current, config('app.timezone')); $temp2 = Carbon::parse($current, config('app.timezone'));
if (!$temp2 instanceof Carbon) { } catch (InvalidFormatException) {
$temp2 = today(config('app.timezone')); $temp2 = today(config('app.timezone'));
} }
$nemDiff = trans('firefly.bill_expected_date', ['date' => $temp2->diffForHumans(today(config('app.timezone')), CarbonInterface::DIFF_RELATIVE_TO_NOW)]); $nemDiff = trans('firefly.bill_expected_date', ['date' => $temp2->diffForHumans(today(config('app.timezone')), CarbonInterface::DIFF_RELATIVE_TO_NOW)]);

View File

@@ -53,9 +53,9 @@ class TransactionGroupEnrichment implements EnrichmentInterface
private array $metaData = []; private array $metaData = [];
private array $notes = []; private array $notes = [];
private array $tags = []; private array $tags = [];
private User $user; private User $user; // @phpstan-ignore-line
private readonly TransactionCurrency $primaryCurrency; private readonly TransactionCurrency $primaryCurrency;
private UserGroup $userGroup; private UserGroup $userGroup; // @phpstan-ignore-line
public function __construct() public function __construct()
{ {
@@ -177,7 +177,7 @@ class TransactionGroupEnrichment implements EnrichmentInterface
->whereIn('attachable_id', $this->journalIds) ->whereIn('attachable_id', $this->journalIds)
->where('attachable_type', TransactionJournal::class) ->where('attachable_type', TransactionJournal::class)
->groupBy('attachable_id') ->groupBy('attachable_id')
->get(['attachable_id', DB::raw('COUNT(id) as nr_of_attachments')]) // @phpstan-ignore-line ->get(['attachable_id', DB::raw('COUNT(id) as nr_of_attachments')])
->toArray() ->toArray()
; ;
foreach ($attachments as $row) { foreach ($attachments as $row) {

View File

@@ -43,8 +43,8 @@ use stdClass;
class WebhookEnrichment implements EnrichmentInterface class WebhookEnrichment implements EnrichmentInterface
{ {
private Collection $collection; private Collection $collection;
private User $user; private User $user; // @phpstan-ignore-line
private UserGroup $userGroup; private UserGroup $userGroup; // @phpstan-ignore-line
private array $ids = []; private array $ids = [];
private array $deliveries = []; private array $deliveries = [];
private array $responses = []; private array $responses = [];

View File

@@ -88,7 +88,7 @@ class ParseDateString
// if regex for YYYY-MM-DD: // if regex for YYYY-MM-DD:
$pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/'; $pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/';
$result = preg_match($pattern, $date); $result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) { if (0 !== $result) {
return $this->parseDefaultDate($date); return $this->parseDefaultDate($date);
} }
@@ -259,7 +259,7 @@ class ParseDateString
{ {
$pattern = '/^xxxx-xx-(0[1-9]|[12]\d|3[01])$/'; $pattern = '/^xxxx-xx-(0[1-9]|[12]\d|3[01])$/';
$result = preg_match($pattern, $date); $result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) { if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a day range.', $date)); app('log')->debug(sprintf('"%s" is a day range.', $date));
return true; return true;
@@ -286,7 +286,7 @@ class ParseDateString
// if regex for xxxx-MM-xx: // if regex for xxxx-MM-xx:
$pattern = '/^xxxx-(0[1-9]|1[012])-xx$/'; $pattern = '/^xxxx-(0[1-9]|1[012])-xx$/';
$result = preg_match($pattern, $date); $result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) { if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a month range.', $date)); app('log')->debug(sprintf('"%s" is a month range.', $date));
return true; return true;
@@ -314,7 +314,7 @@ class ParseDateString
// if regex for YYYY-xx-xx: // if regex for YYYY-xx-xx:
$pattern = '/^(19|20)\d\d-xx-xx$/'; $pattern = '/^(19|20)\d\d-xx-xx$/';
$result = preg_match($pattern, $date); $result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) { if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a year range.', $date)); app('log')->debug(sprintf('"%s" is a year range.', $date));
return true; return true;
@@ -342,7 +342,7 @@ class ParseDateString
// if regex for xxxx-MM-DD: // if regex for xxxx-MM-DD:
$pattern = '/^xxxx-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/'; $pattern = '/^xxxx-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/';
$result = preg_match($pattern, $date); $result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) { if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a month/day range.', $date)); app('log')->debug(sprintf('"%s" is a month/day range.', $date));
return true; return true;
@@ -371,7 +371,7 @@ class ParseDateString
// if regex for YYYY-xx-DD: // if regex for YYYY-xx-DD:
$pattern = '/^(19|20)\d\d-xx-(0[1-9]|[12]\d|3[01])$/'; $pattern = '/^(19|20)\d\d-xx-(0[1-9]|[12]\d|3[01])$/';
$result = preg_match($pattern, $date); $result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) { if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a day/year range.', $date)); app('log')->debug(sprintf('"%s" is a day/year range.', $date));
return true; return true;
@@ -400,7 +400,7 @@ class ParseDateString
// if regex for YYYY-MM-xx: // if regex for YYYY-MM-xx:
$pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-xx$/'; $pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-xx$/';
$result = preg_match($pattern, $date); $result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) { if (0 !== $result) {
app('log')->debug(sprintf('"%s" is a month/year range.', $date)); app('log')->debug(sprintf('"%s" is a month/year range.', $date));
return true; return true;

View File

@@ -146,7 +146,7 @@ trait ConvertsDataTypes
// clear zalgo text (TODO also in API v2) // clear zalgo text (TODO also in API v2)
$string = preg_replace('/(\pM{2})\pM+/u', '\1', $string); $string = preg_replace('/(\pM{2})\pM+/u', '\1', $string);
return trim((string)$string); return trim($string);
} }
public function convertIban(string $field): string public function convertIban(string $field): string