mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-20 08:30:06 +00:00
Refactor old methods.
This commit is contained in:
@@ -55,12 +55,9 @@ class SetSourceAccount implements ActionInterface
|
||||
*/
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
/** @var TransactionJournal $object */
|
||||
/** @var AccountRepositoryInterface repository */
|
||||
/** @var Transaction $destination */
|
||||
|
||||
$user = User::find($journal['user_id']);
|
||||
$type = $journal['transaction_type_type'];
|
||||
/** @var TransactionJournal|null $object */
|
||||
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
@@ -83,6 +80,7 @@ class SetSourceAccount implements ActionInterface
|
||||
}
|
||||
|
||||
// new source account must be different from the current destination account:
|
||||
/** @var Transaction|null $destination */
|
||||
$destination = $object->transactions()->where('amount', '>', 0)->first();
|
||||
if (null === $destination) {
|
||||
Log::error('Could not find destination transaction.');
|
||||
@@ -110,11 +108,6 @@ class SetSourceAccount implements ActionInterface
|
||||
if (TransactionType::DEPOSIT === $type) {
|
||||
$newAccount = $this->findRevenueAccount();
|
||||
}
|
||||
if (null === $newAccount) {
|
||||
Log::error('New account is NULL');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('New source account is #%d ("%s").', $newAccount->id, $newAccount->name));
|
||||
|
||||
@@ -145,9 +138,9 @@ class SetSourceAccount implements ActionInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Account|null
|
||||
* @return Account
|
||||
*/
|
||||
private function findRevenueAccount(): ?Account
|
||||
private function findRevenueAccount(): Account
|
||||
{
|
||||
$allowed = config('firefly.expected_source_types.source.Deposit');
|
||||
$account = $this->repository->findByName($this->action->action_value, $allowed);
|
||||
|
||||
Reference in New Issue
Block a user