PHPstan fixes.

This commit is contained in:
James Cole
2023-11-05 08:15:17 +01:00
parent ff599795d3
commit c1cc71f85c
48 changed files with 101 additions and 166 deletions

View File

@@ -111,7 +111,7 @@ class OperationsRepository implements OperationsRepositoryInterface
];
$array[$currencyId]['transaction_journals'][$journalId] = [
'amount' => app('steam')->$direction((string)$journal['amount']),
'amount' => app('steam')->$direction((string)$journal['amount']), // @phpstan-ignore-line
'date' => $journal['date'],
'transaction_journal_id' => $journalId,
'budget_name' => $journal['budget_name'],
@@ -268,7 +268,7 @@ class OperationsRepository implements OperationsRepositoryInterface
'currency_code' => $journal['currency_code'],
'currency_decimal_places' => $journal['currency_decimal_places'],
];
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->$direction($journal['amount']));
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->$direction($journal['amount']));// @phpstan-ignore-line
// also do foreign amount:
$foreignId = (int)$journal['foreign_currency_id'];
@@ -281,7 +281,7 @@ class OperationsRepository implements OperationsRepositoryInterface
'currency_code' => $journal['foreign_currency_code'],
'currency_decimal_places' => $journal['foreign_currency_decimal_places'],
];
$array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], app('steam')->$direction($journal['foreign_amount']));
$array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], app('steam')->$direction($journal['foreign_amount']));// @phpstan-ignore-line
}
}
@@ -328,7 +328,7 @@ class OperationsRepository implements OperationsRepositoryInterface
'currency_code' => $journal['currency_code'],
'currency_decimal_places' => $journal['currency_decimal_places'],
];
$array[$key]['sum'] = bcadd($array[$key]['sum'], app('steam')->$method((string)$journal['amount']));
$array[$key]['sum'] = bcadd($array[$key]['sum'], app('steam')->$method((string)$journal['amount']));// @phpstan-ignore-line
// also do foreign amount:
if (0 !== (int)$journal['foreign_currency_id']) {
@@ -343,7 +343,7 @@ class OperationsRepository implements OperationsRepositoryInterface
'currency_code' => $journal['foreign_currency_code'],
'currency_decimal_places' => $journal['foreign_currency_decimal_places'],
];
$array[$key]['sum'] = bcadd($array[$key]['sum'], app('steam')->$method((string)$journal['foreign_amount']));
$array[$key]['sum'] = bcadd($array[$key]['sum'], app('steam')->$method((string)$journal['foreign_amount']));// @phpstan-ignore-line
}
}

View File

@@ -137,7 +137,7 @@ class BillRepository implements BillRepositoryInterface
public function findBill(?int $billId, ?string $billName): ?Bill
{
if (null !== $billId) {
$searchResult = $this->find((int)$billId);
$searchResult = $this->find($billId);
if (null !== $searchResult) {
app('log')->debug(sprintf('Found bill based on #%d, will return it.', $billId));
@@ -145,7 +145,7 @@ class BillRepository implements BillRepositoryInterface
}
}
if (null !== $billName) {
$searchResult = $this->findByName((string)$billName);
$searchResult = $this->findByName($billName);
if (null !== $searchResult) {
app('log')->debug(sprintf('Found bill based on "%s", will return it.', $billName));

View File

@@ -530,7 +530,7 @@ class BudgetRepository implements BudgetRepositoryInterface
$result = $this->find((int)$budgetId);
if (null === $result && null !== $budgetName && '' !== $budgetName) {
app('log')->debug(sprintf('Searching for budget with name %s...', $budgetName));
$result = $this->findByName((string)$budgetName);
$result = $this->findByName($budgetName);
}
if (null !== $result) {
app('log')->debug(sprintf('Found budget #%d: %s', $result->id, $result->name));

View File

@@ -382,8 +382,8 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
*/
public function updateLink(TransactionJournalLink $journalLink, array $data): TransactionJournalLink
{
$journalLink->source_id = $data['inward_id'] ?: $journalLink->source_id;
$journalLink->destination_id = $data['outward_id'] ?: $journalLink->destination_id;
$journalLink->source_id = null === $data['inward_id'] ? $journalLink->source_id : $data['inward_id'];
$journalLink->destination_id = null === $data['outward_id'] ? $journalLink->destination_id : $data['outward_id'];
$journalLink->save();
if (array_key_exists('link_type_name', $data)) {
$linkType = LinkType::whereName($data['link_type_name'])->first();
@@ -394,7 +394,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
$journalLink->refresh();
}
$journalLink->link_type_id = $data['link_type_id'] ?: $journalLink->link_type_id;
$journalLink->link_type_id = null === $data['link_type_id'] ? $journalLink->link_type_id : $data['link_type_id'];
$journalLink->save();
if (array_key_exists('notes', $data) && null !== $data['notes']) {
$this->setNoteText($journalLink, $data['notes']);

View File

@@ -68,7 +68,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
app('log')->debug('Searching for piggy information.');
if (null !== $piggyBankId) {
$searchResult = $this->find((int)$piggyBankId);
$searchResult = $this->find($piggyBankId);
if (null !== $searchResult) {
app('log')->debug(sprintf('Found piggy based on #%d, will return it.', $piggyBankId));
@@ -76,7 +76,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
}
}
if (null !== $piggyBankName) {
$searchResult = $this->findByName((string)$piggyBankName);
$searchResult = $this->findByName($piggyBankName);
if (null !== $searchResult) {
app('log')->debug(sprintf('Found piggy based on "%s", will return it.', $piggyBankName));
@@ -227,11 +227,11 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
$amount = null;
if ((int)$source->transaction_currency_id === (int)$currency->id) {
app('log')->debug('Use normal amount');
$amount = app('steam')->$operator($source->amount);
$amount = app('steam')->$operator($source->amount); // @phpstan-ignore-line
}
if ((int)$source->foreign_currency_id === (int)$currency->id) {
app('log')->debug('Use foreign amount');
$amount = app('steam')->$operator($source->foreign_amount);
$amount = app('steam')->$operator($source->foreign_amount); // @phpstan-ignore-line
}
if (null === $amount) {
app('log')->debug('No match on currency, so amount remains null, return "0".');

View File

@@ -85,7 +85,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
'recurrences', 'rules', 'ruleGroups', 'tags', 'transactionGroups', 'transactionJournals', 'piggyBanks', 'accounts', 'webhooks',
];
foreach ($objects as $object) {
foreach ($userGroup->$object()->get() as $item) {
foreach ($userGroup->$object()->get() as $item) { // @phpstan-ignore-line
$item->delete();
}
}
@@ -135,7 +135,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
}
if (null !== $existingGroup) {
// group already exists
$groupName = sprintf('%s-%s', $user->email, substr(sha1((string)(rand(1000, 9999) . microtime())), 0, 4));
$groupName = sprintf('%s-%s', $user->email, substr(sha1((rand(1000, 9999) . microtime())), 0, 4));
}
$loop++;
}