Fix various phpstan issues.

This commit is contained in:
James Cole
2023-11-04 07:18:03 +01:00
parent dc45131f73
commit ef428a0226
42 changed files with 104 additions and 174 deletions

View File

@@ -56,7 +56,7 @@ class AppendNotesToDescription implements ActionInterface
public function actOnArray(array $journal): bool
{
app('log')->debug('Now in AppendNotesToDescription');
/** @var TransactionJournal $object */
/** @var TransactionJournal|null $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
app('log')->error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));

View File

@@ -134,23 +134,20 @@ class ConvertToTransfer implements ActionInterface
}
return $res;
}
if (TransactionType::DEPOSIT === $type) {
app('log')->debug('Going to transform a deposit to a transfer.');
try {
$res = $this->convertDepositArray($object, $opposing);
} catch (FireflyException $e) {
app('log')->debug('Could not convert deposit to transfer.');
app('log')->error($e->getMessage());
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
return false;
}
if (false !== $res) {
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionType::DEPOSIT, TransactionType::TRANSFER));
}
return $res;
// can only be a deposit at this point.
app('log')->debug('Going to transform a deposit to a transfer.');
try {
$res = $this->convertDepositArray($object, $opposing);
} catch (FireflyException $e) {
app('log')->debug('Could not convert deposit to transfer.');
app('log')->error($e->getMessage());
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
return false;
}
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.unsupported_transaction_type_transfer', ['type' => $type])));
return false;
if (false !== $res) {
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionType::DEPOSIT, TransactionType::TRANSFER));
}
return $res;
}
/**
@@ -176,7 +173,7 @@ class ConvertToTransfer implements ActionInterface
*/
private function getDestinationType(int $journalId): string
{
/** @var TransactionJournal $journal */
/** @var TransactionJournal|null $journal */
$journal = TransactionJournal::find($journalId);
if (null === $journal) {
app('log')->error(sprintf('Journal #%d does not exist. Cannot convert to transfer.', $journalId));

View File

@@ -99,23 +99,20 @@ class ConvertToWithdrawal implements ActionInterface
return $res;
}
if (TransactionType::TRANSFER === $type) {
app('log')->debug('Going to transform a transfer to a withdrawal.');
// can only be transfer at this point.
app('log')->debug('Going to transform a transfer to a withdrawal.');
try {
$res = $this->convertTransferArray($object);
} catch (JsonException | FireflyException $e) {
app('log')->debug('Could not convert transfer to deposit.');
app('log')->error($e->getMessage());
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
return false;
}
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionType::TRANSFER, TransactionType::WITHDRAWAL));
return $res;
try {
$res = $this->convertTransferArray($object);
} catch (JsonException | FireflyException $e) {
app('log')->debug('Could not convert transfer to deposit.');
app('log')->error($e->getMessage());
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
return false;
}
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.unsupported_transaction_type_withdrawal', ['type' => $type])));
return false;
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionType::TRANSFER, TransactionType::WITHDRAWAL));
return $res;
}
/**

View File

@@ -53,13 +53,14 @@ class MoveDescriptionToNotes implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
/** @var TransactionJournal $object */
/** @var TransactionJournal|null $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
app('log')->error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_other_user')));
return false;
}
/** @var Note|null $note */
$note = $object->notes()->first();
if (null === $note) {
$note = new Note();

View File

@@ -59,7 +59,7 @@ class MoveNotesToDescription implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
/** @var TransactionJournal $object */
/** @var TransactionJournal|null $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
app('log')->error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));

View File

@@ -75,9 +75,9 @@ class SwitchAccounts implements ActionInterface
return false;
}
/** @var Transaction $sourceTransaction */
/** @var Transaction|null $sourceTransaction */
$sourceTransaction = $object->transactions()->where('amount', '<', 0)->first();
/** @var Transaction $destTransaction */
/** @var Transaction|null $destTransaction */
$destTransaction = $object->transactions()->where('amount', '>', 0)->first();
if (null === $sourceTransaction || null === $destTransaction) {
app('log')->error(sprintf('Journal #%d has no source or destination transaction (rule #%d), cannot switch accounts.', $journal['transaction_journal_id'], $this->action->rule_id));