Fix phpstan issues.

This commit is contained in:
James Cole
2023-11-05 19:55:39 +01:00
parent 1d2e95f5af
commit 6f6b8d9b3e
33 changed files with 151 additions and 69 deletions

View File

@@ -74,7 +74,7 @@ class AccountTransformer extends AbstractTransformer
$this->currencies[$id] = $currency;
}
foreach ($meta as $entry) {
$id = (int)$entry->account_id;
$id = $entry->account_id;
$this->accountMeta[$id][$entry->name] = $entry->data;
}
// get account types:
@@ -84,7 +84,7 @@ class AccountTransformer extends AbstractTransformer
->get(['accounts.id', 'account_types.type']);
/** @var AccountType $row */
foreach ($accountTypes as $row) {
$this->accountTypes[(int)$row->id] = (string)config(sprintf('firefly.shortNamesByFullName.%s', $row->type));
$this->accountTypes[$row->id] = (string)config(sprintf('firefly.shortNamesByFullName.%s', $row->type));
}
}
@@ -115,7 +115,7 @@ class AccountTransformer extends AbstractTransformer
// various meta
$accountRole = $this->accountMeta[$id]['account_role'] ?? null;
$accountType = $this->accountTypes[$id];
$order = (int)$account->order;
$order = $account->order;
// no currency? use default
$currency = $this->default;

View File

@@ -62,8 +62,8 @@ class BillTransformer extends AbstractTransformer
// start with currencies:
/** @var Bill $object */
foreach ($objects as $object) {
$id = (int)$object->transaction_currency_id;
$bills[] = (int)$object->id;
$id = $object->transaction_currency_id;
$bills[] = $object->id;
$currencies[$id] = $currencies[$id] ?? TransactionCurrency::find($id);
}
$this->currencies = $currencies;
@@ -72,7 +72,7 @@ class BillTransformer extends AbstractTransformer
$notes = Note::whereNoteableType(Bill::class)->whereIn('noteable_id', array_keys($bills))->get();
/** @var Note $note */
foreach ($notes as $note) {
$id = (int)$note->noteable_id;
$id = $note->noteable_id;
$this->notes[$id] = $note;
}
// grab object groups:
@@ -84,7 +84,7 @@ class BillTransformer extends AbstractTransformer
foreach ($set as $entry) {
$billId = (int)$entry->object_groupable_id;
$id = (int)$entry->object_group_id;
$order = (int)$entry->order;
$order = $entry->order;
$this->groups[$billId] = [
'object_group_id' => $id,
'object_group_title' => $entry->title,
@@ -143,12 +143,12 @@ class BillTransformer extends AbstractTransformer
'transaction_group_id' => (string)$journal->id,
'transaction_journal_id' => (string)$journal->transaction_group_id,
'date' => $journal->date->toAtomString(),
'currency_id' => (int)$currencies[$currencyId]->id,
'currency_id' => $currencies[$currencyId]->id,
'currency_code' => $currencies[$currencyId]->code,
'currency_name' => $currencies[$currencyId]->name,
'currency_symbol' => $currencies[$currencyId]->symbol,
'currency_decimal_places' => (int)$currencies[$currencyId]->decimal_places,
'native_currency_id' => (int)$currencies[$currencyId]->id,
'native_currency_id' => $currencies[$currencyId]->id,
'native_currency_code' => $currencies[$currencyId]->code,
'native_currency_symbol' => $currencies[$currencyId]->symbol,
'native_currency_decimal_places' => (int)$currencies[$currencyId]->decimal_places,
@@ -180,11 +180,11 @@ class BillTransformer extends AbstractTransformer
*/
public function transform(Bill $bill): array
{
$paidData = $this->paidDates[(int)$bill->id] ?? [];
$nextExpectedMatch = $this->nextExpectedMatch($bill, $this->paidDates[(int)$bill->id] ?? []);
$paidData = $this->paidDates[$bill->id] ?? [];
$nextExpectedMatch = $this->nextExpectedMatch($bill, $this->paidDates[$bill->id] ?? []);
$payDates = $this->payDates($bill);
$currency = $this->currencies[$bill->transaction_currency_id];
$group = $this->groups[(int)$bill->id] ?? null;
$group = $this->groups[$bill->id] ?? null;
// date for currency conversion
/** @var Carbon|null $startParam */
@@ -195,7 +195,7 @@ class BillTransformer extends AbstractTransformer
$nextExpectedMatchDiff = $this->getNextExpectedMatchDiff($nextExpectedMatch, $payDates);
return [
'id' => (int)$bill->id,
'id' => $bill->id,
'created_at' => $bill->created_at->toAtomString(),
'updated_at' => $bill->updated_at->toAtomString(),
'name' => $bill->name,
@@ -219,8 +219,8 @@ class BillTransformer extends AbstractTransformer
'repeat_freq' => $bill->repeat_freq,
'skip' => (int)$bill->skip,
'active' => $bill->active,
'order' => (int)$bill->order,
'notes' => $this->notes[(int)$bill->id] ?? null,
'order' => $bill->order,
'notes' => $this->notes[$bill->id] ?? null,
'object_group_id' => $group ? $group['object_group_id'] : null,
'object_group_order' => $group ? $group['object_group_order'] : null,
'object_group_title' => $group ? $group['object_group_title'] : null,

View File

@@ -91,7 +91,7 @@ class PiggyBankTransformer extends AbstractTransformer
/** @var AccountMeta $preference */
foreach ($currencyPreferences as $preference) {
$currencyId = (int)$preference->data;
$accountId = (int)$preference->account_id;
$accountId = $preference->account_id;
$currencies[$currencyId] = $currencies[$currencyId] ?? TransactionJournal::find($currencyId);
$this->currencies[$accountId] = $currencies[$currencyId];
}
@@ -105,7 +105,7 @@ class PiggyBankTransformer extends AbstractTransformer
foreach ($set as $entry) {
$piggyBankId = (int)$entry->object_groupable_id;
$id = (int)$entry->object_group_id;
$order = (int)$entry->order;
$order = $entry->order;
$this->groups[$piggyBankId] = [
'object_group_id' => $id,
'object_group_title' => $entry->title,
@@ -118,7 +118,7 @@ class PiggyBankTransformer extends AbstractTransformer
$repetitions = PiggyBankRepetition::whereIn('piggy_bank_id', $piggyBanks)->get();
/** @var PiggyBankRepetition $repetition */
foreach ($repetitions as $repetition) {
$this->repetitions[(int)$repetition->piggy_bank_id] = [
$this->repetitions[$repetition->piggy_bank_id] = [
'amount' => $repetition->currentamount,
];
}
@@ -128,7 +128,7 @@ class PiggyBankTransformer extends AbstractTransformer
$notes = Note::whereNoteableType(PiggyBank::class)->whereIn('noteable_id', array_keys($piggyBanks))->get();
/** @var Note $note */
foreach ($notes as $note) {
$id = (int)$note->noteable_id;
$id = $note->noteable_id;
$this->notes[$id] = $note;
}
@@ -180,15 +180,15 @@ class PiggyBankTransformer extends AbstractTransformer
$nativeSavePerMonth = null;
$startDate = $piggyBank->startdate?->format('Y-m-d');
$targetDate = $piggyBank->targetdate?->format('Y-m-d');
$accountId = (int)$piggyBank->account_id;
$accountId = $piggyBank->account_id;
$accountName = $this->accounts[$accountId]['name'] ?? null;
$currency = $this->currencies[$accountId] ?? $this->default;
$currentAmount = app('steam')->bcround($this->repetitions[(int)$piggyBank->id]['amount'] ?? '0', $currency->decimal_places);
$currentAmount = app('steam')->bcround($this->repetitions[$piggyBank->id]['amount'] ?? '0', $currency->decimal_places);
$nativeCurrentAmount = $this->converter->convert($this->default, $currency, today(), $currentAmount);
$targetAmount = $piggyBank->targetamount;
$nativeTargetAmount = $this->converter->convert($this->default, $currency, today(), $targetAmount);
$note = $this->notes[(int)$piggyBank->id] ?? null;
$group = $this->groups[(int)$piggyBank->id] ?? null;
$note = $this->notes[$piggyBank->id] ?? null;
$group = $this->groups[$piggyBank->id] ?? null;
if (0 !== bccomp($targetAmount, '0')) { // target amount is not 0.00
$leftToSave = bcsub($targetAmount, $currentAmount);
@@ -224,7 +224,7 @@ class PiggyBankTransformer extends AbstractTransformer
'native_save_per_month' => $nativeSavePerMonth,
'start_date' => $startDate,
'target_date' => $targetDate,
'order' => (int)$piggyBank->order,
'order' => $piggyBank->order,
'active' => $piggyBank->active,
'notes' => $note,
'object_group_id' => $group ? $group['object_group_id'] : null,

View File

@@ -49,7 +49,7 @@ class PreferenceTransformer extends AbstractTransformer
public function transform(Preference $preference): array
{
return [
'id' => (int)$preference->id,
'id' => $preference->id,
'created_at' => $preference->created_at->toAtomString(),
'updated_at' => $preference->updated_at->toAtomString(),
'name' => $preference->name,

View File

@@ -85,7 +85,7 @@ class TransactionGroupTransformer extends AbstractTransformer
$notes = Note::whereNoteableType(TransactionJournal::class)->whereIn('noteable_id', array_keys($journals))->get();
/** @var Note $note */
foreach ($notes as $note) {
$id = (int)$note->noteable_id;
$id = $note->noteable_id;
$this->notes[$id] = $note;
}

View File

@@ -57,7 +57,7 @@ class UserGroupTransformer extends AbstractTransformer
$user = auth()->user();
/** @var UserGroup $userGroup */
foreach ($objects as $userGroup) {
$userGroupId = (int)$userGroup->id;
$userGroupId = $userGroup->id;
$access = $user->hasRoleInGroup($userGroup, UserRoleEnum::VIEW_MEMBERSHIPS, true, true);
if ($access) {
$groupMemberships = $userGroup->groupMemberships()->get();
@@ -84,11 +84,11 @@ class UserGroupTransformer extends AbstractTransformer
public function transform(UserGroup $userGroup): array
{
$return = [
'id' => (int)$userGroup->id,
'id' => $userGroup->id,
'created_at' => $userGroup->created_at->toAtomString(),
'updated_at' => $userGroup->updated_at->toAtomString(),
'title' => $userGroup->title,
'members' => $this->memberships[(int)$userGroup->id] ?? [],
'members' => $this->memberships[$userGroup->id] ?? [],
];
// if the user has a specific role in this group, then collect the memberships.