Various code cleanup and fixed alignments.

This commit is contained in:
James Cole
2024-01-01 14:43:56 +01:00
parent 1368aafe5f
commit f963ac63f1
443 changed files with 3668 additions and 3672 deletions

View File

@@ -54,12 +54,12 @@ class UpdatePiggybank implements ActionInterface
// refresh the transaction type.
/** @var User $user */
$user = User::find($journal['user_id']);
$user = User::find($journal['user_id']);
/** @var TransactionJournal $journalObj */
$journalObj = $user->transactionJournals()->find($journal['transaction_journal_id']);
$journalObj = $user->transactionJournals()->find($journal['transaction_journal_id']);
$piggyBank = $this->findPiggyBank($user);
$piggyBank = $this->findPiggyBank($user);
if (null === $piggyBank) {
app('log')->info(
sprintf('No piggy bank named "%s", cant execute action #%d of rule #%d', $this->action->action_value, $this->action->id, $this->action->rule_id)
@@ -72,7 +72,7 @@ class UpdatePiggybank implements ActionInterface
app('log')->debug(sprintf('Found piggy bank #%d ("%s")', $piggyBank->id, $piggyBank->name));
/** @var Transaction $source */
$source = $journalObj->transactions()->where('amount', '<', 0)->first();
$source = $journalObj->transactions()->where('amount', '<', 0)->first();
/** @var Transaction $destination */
$destination = $journalObj->transactions()->where('amount', '>', 0)->first();
@@ -142,11 +142,11 @@ class UpdatePiggybank implements ActionInterface
$repository->setUser($journal->user);
// how much can we remove from this piggy bank?
$toRemove = $repository->getCurrentAmount($piggyBank);
$toRemove = $repository->getCurrentAmount($piggyBank);
app('log')->debug(sprintf('Amount is %s, max to remove is %s', $amount, $toRemove));
// if $amount is bigger than $toRemove, shrink it.
$amount = -1 === bccomp($amount, $toRemove) ? $amount : $toRemove;
$amount = -1 === bccomp($amount, $toRemove) ? $amount : $toRemove;
app('log')->debug(sprintf('Amount is now %s', $amount));
// if amount is zero, stop.
@@ -174,7 +174,7 @@ class UpdatePiggybank implements ActionInterface
// how much can we add to the piggy bank?
if (0 !== bccomp($piggyBank->targetamount, '0')) {
$toAdd = bcsub($piggyBank->targetamount, $repository->getCurrentAmount($piggyBank));
$toAdd = bcsub($piggyBank->targetamount, $repository->getCurrentAmount($piggyBank));
app('log')->debug(sprintf('Max amount to add to piggy bank is %s, amount is %s', $toAdd, $amount));
// update amount to fit: