Refactor old methods.

This commit is contained in:
James Cole
2021-04-06 13:30:09 +02:00
parent 5ceef2e9c3
commit 69b1769f22
54 changed files with 191 additions and 478 deletions

View File

@@ -22,20 +22,11 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
/**
* Interface ActionInterface.
*/
interface ActionInterface
{
/**
* ActionInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action);
/**
* Execute the action on an array. Returns "true" if the action was a success and the action
* was applied. Returns false if otherwise.

View File

@@ -31,15 +31,6 @@ use Log;
*/
class ClearBudget implements ActionInterface
{
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action)
{
}
/**
* @inheritDoc
*/

View File

@@ -31,15 +31,6 @@ use Log;
*/
class ClearCategory implements ActionInterface
{
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action)
{
}
/**
* @inheritDoc
*/

View File

@@ -32,15 +32,6 @@ use Log;
*/
class ClearNotes implements ActionInterface
{
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action)
{
}
/**
* @inheritDoc
*/

View File

@@ -149,7 +149,6 @@ class ConvertToDeposit implements ActionInterface
$revenue = $factory->findOrCreate($revenueName, AccountType::REVENUE);
Log::debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $this->action->action_value, $journal['source_account_name']));
unset($source);
// update source transaction(s) to be revenue account
DB::table('transactions')

View File

@@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
@@ -34,15 +33,6 @@ use Log;
*/
class DeleteTransaction implements ActionInterface
{
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action)
{
}
/**
* @inheritDoc
*/

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use DB;
use FireflyIII\Models\RuleAction;
use Log;
/**
@@ -31,15 +30,6 @@ use Log;
*/
class RemoveAllTags implements ActionInterface
{
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action)
{
}
/**
* @inheritDoc
*/
@@ -50,4 +40,5 @@ class RemoveAllTags implements ActionInterface
return true;
}
}

View File

@@ -56,12 +56,9 @@ class SetDestinationAccount implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
/** @var TransactionJournal $object */
/** @var AccountRepositoryInterface repository */
/** @var Transaction $source */
$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);
@@ -86,6 +83,7 @@ class SetDestinationAccount implements ActionInterface
}
// new destination account must be different from the current source account:
/** @var Transaction|null $source */
$source = $object->transactions()->where('amount', '<', 0)->first();
if (null === $source) {
Log::error('Could not find source transaction.');
@@ -113,11 +111,6 @@ class SetDestinationAccount implements ActionInterface
if (TransactionType::WITHDRAWAL === $type) {
$newAccount = $this->findExpenseAccount();
}
if (null === $newAccount) {
Log::error('New expense account is NULL');
return false;
}
Log::debug(sprintf('New destination account is #%d ("%s").', $newAccount->id, $newAccount->name));
@@ -150,9 +143,9 @@ class SetDestinationAccount implements ActionInterface
}
/**
* @return Account|null
* @return Account
*/
private function findExpenseAccount(): ?Account
private function findExpenseAccount(): Account
{
$account = $this->repository->findByName($this->action->action_value, [AccountType::EXPENSE]);
if (null === $account) {

View File

@@ -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);