Clean up code.

This commit is contained in:
James Cole
2025-05-04 17:41:26 +02:00
parent e28e538272
commit 0573bf2402
147 changed files with 1758 additions and 1770 deletions

View File

@@ -140,6 +140,29 @@ class UpdatePiggyBank implements ActionInterface
return $repository->findByName($name);
}
private function getAccounts(TransactionJournal $journal): array
{
return [
'source' => $journal->transactions()->where('amount', '<', '0')->first()?->account,
'destination' => $journal->transactions()->where('amount', '>', '0')->first()?->account,
];
}
private function isConnected(PiggyBank $piggyBank, ?Account $link): bool
{
if (null === $link) {
return false;
}
foreach ($piggyBank->accounts as $account) {
if ($account->id === $link->id) {
return true;
}
}
Log::debug(sprintf('Piggy bank is not connected to account #%d "%s"', $link->id, $link->name));
return false;
}
private function removeAmount(PiggyBank $piggyBank, array $array, TransactionJournal $journal, Account $account, string $amount): void
{
$repository = app(PiggyBankRepositoryInterface::class);
@@ -208,27 +231,4 @@ class UpdatePiggyBank implements ActionInterface
$repository->addAmount($piggyBank, $account, $amount, $journal);
}
private function getAccounts(TransactionJournal $journal): array
{
return [
'source' => $journal->transactions()->where('amount', '<', '0')->first()?->account,
'destination' => $journal->transactions()->where('amount', '>', '0')->first()?->account,
];
}
private function isConnected(PiggyBank $piggyBank, ?Account $link): bool
{
if (null === $link) {
return false;
}
foreach ($piggyBank->accounts as $account) {
if ($account->id === $link->id) {
return true;
}
}
Log::debug(sprintf('Piggy bank is not connected to account #%d "%s"', $link->id, $link->name));
return false;
}
}