Various code cleanup.

This commit is contained in:
James Cole
2023-11-05 19:41:37 +01:00
parent a0564751d6
commit 1d2e95f5af
136 changed files with 1171 additions and 514 deletions

View File

@@ -75,7 +75,7 @@ class ConvertToTransfer implements ActionInterface
$type = $object->transactionType->type;
$user = $object->user;
$journalId = (int)$object->id;
$journalId = $object->id;
if (TransactionType::TRANSFER === $type) {
app('log')->error(
sprintf('Journal #%d is already a transfer so cannot be converted (rule #%d).', $object->id, $this->action->rule_id)
@@ -196,7 +196,7 @@ class ConvertToTransfer implements ActionInterface
private function convertWithdrawalArray(TransactionJournal $journal, Account $opposing): bool
{
$sourceAccount = $this->getSourceAccount($journal);
if ((int)$sourceAccount->id === (int)$opposing->id) {
if ($sourceAccount->id === $opposing->id) {
app('log')->error(
vsprintf(
'Journal #%d has already has "%s" as a source asset. ConvertToTransfer failed. (rule #%d).',
@@ -255,7 +255,7 @@ class ConvertToTransfer implements ActionInterface
private function convertDepositArray(TransactionJournal $journal, Account $opposing): bool
{
$destAccount = $this->getDestinationAccount($journal);
if ((int)$destAccount->id === (int)$opposing->id) {
if ($destAccount->id === $opposing->id) {
app('log')->error(
vsprintf(
'Journal #%d has already has "%s" as a destination asset. ConvertToTransfer failed. (rule #%d).',

View File

@@ -87,7 +87,7 @@ class SetBudget implements ActionInterface
$object = $user->transactionJournals()->find($journal['transaction_journal_id']);
$oldBudget = $object->budgets()->first();
$oldBudgetName = $oldBudget?->name;
if ((int)$oldBudget?->id === (int)$budget->id) {
if ((int)$oldBudget?->id === $budget->id) {
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.already_linked_to_budget', ['name' => $budget->name])));
return false;
}

View File

@@ -91,7 +91,7 @@ class SetCategory implements ActionInterface
$object = $user->transactionJournals()->find($journal['transaction_journal_id']);
$oldCategory = $object->categories()->first();
$oldCategoryName = $oldCategory?->name;
if ((int)$oldCategory?->id === (int)$category->id) {
if ((int)$oldCategory?->id === $category->id) {
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.already_linked_to_category', ['name' => $category->name])));
return false;
}

View File

@@ -99,7 +99,7 @@ class SetDestinationAccount implements ActionInterface
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_source_transaction_account')));
return false;
}
if (null !== $newAccount && (int)$newAccount->id === (int)$source->account_id) {
if (null !== $newAccount && $newAccount->id === $source->account_id) {
app('log')->error(
sprintf(
'New destination account ID #%d and current source account ID #%d are the same. Do nothing.',

View File

@@ -94,7 +94,7 @@ class SetSourceAccount implements ActionInterface
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_destination_transaction_account')));
return false;
}
if (null !== $newAccount && (int)$newAccount->id === (int)$destination->account_id) {
if (null !== $newAccount && $newAccount->id === $destination->account_id) {
app('log')->error(
sprintf(
'New source account ID #%d and current destination account ID #%d are the same. Do nothing.',

View File

@@ -84,7 +84,7 @@ class SwitchAccounts implements ActionInterface
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_accounts')));
return false;
}
$sourceAccountId = (int)$sourceTransaction->account_id;
$sourceAccountId = $sourceTransaction->account_id;
$destinationAccountId = $destTransaction->account_id;
$sourceTransaction->account_id = $destinationAccountId;
$destTransaction->account_id = $sourceAccountId;

View File

@@ -62,7 +62,6 @@ class UpdatePiggybank implements ActionInterface
$user = User::find($journal['user_id']);
/** @var TransactionJournal $journalObj */
$journalObj = $user->transactionJournals()->find($journal['transaction_journal_id']);
$type = TransactionType::find((int)$journalObj->transaction_type_id);
$piggyBank = $this->findPiggyBank($user);
if (null === $piggyBank) {
@@ -80,7 +79,7 @@ class UpdatePiggybank implements ActionInterface
/** @var Transaction $destination */
$destination = $journalObj->transactions()->where('amount', '>', 0)->first();
if ((int)$source->account_id === (int)$piggyBank->account_id) {
if ($source->account_id === $piggyBank->account_id) {
app('log')->debug('Piggy bank account is linked to source, so remove amount from piggy bank.');
$this->removeAmount($piggyBank, $journalObj, $destination->amount);
@@ -101,7 +100,7 @@ class UpdatePiggybank implements ActionInterface
return true;
}
if ((int)$destination->account_id === (int)$piggyBank->account_id) {
if ($destination->account_id === $piggyBank->account_id) {
app('log')->debug('Piggy bank account is linked to source, so add amount to piggy bank.');
$this->addAmount($piggyBank, $journalObj, $destination->amount);