Remove unnecessary loops.

This commit is contained in:
James Cole
2019-08-10 07:04:54 +02:00
parent 7b0ccdbdb4
commit cb1db06a7c
5 changed files with 5 additions and 61 deletions

View File

@@ -47,7 +47,6 @@ class RemoveTag implements ActionInterface
/**
* Remove tag X
* TODO the filter is no longer necessary.
* @param TransactionJournal $journal
*
* @return bool
@@ -56,12 +55,7 @@ class RemoveTag implements ActionInterface
{
// if tag does not exist, no need to continue:
$name = $this->action->action_value;
/** @var Tag $tag */
$tag = $journal->user->tags()->get()->filter(
function (Tag $tag) use ($name) {
return $tag->tag === $name;
}
)->first();
$tag = $journal->user->tags()->where('tag', $name)->first();
if (null !== $tag) {
Log::debug(sprintf('RuleAction RemoveTag removed tag #%d ("%s") from journal #%d.', $tag->id, $tag->tag, $journal->id));

View File

@@ -22,12 +22,9 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Models\Budget;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Log;
/**
@@ -50,27 +47,15 @@ class SetBudget implements ActionInterface
/**
* Set budget.
* TODO the filter is no longer necessary.
*
* @param TransactionJournal $journal
*
* @return bool
*/
public function act(TransactionJournal $journal): bool
{
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
$repository->setUser($journal->user);
$search = $this->action->action_value;
$budgets = $repository->getActiveBudgets();
// TODO no longer need to loop like this
$budget = $budgets->filter(
static function (Budget $current) use ($search) {
return $current->name === $search;
}
)->first();
$budget = $journal->user->budgets()->where('name', $search)->first();
if (null === $budget) {
Log::debug(sprintf('RuleAction SetBudget could not set budget of journal #%d to "%s" because no such budget exists.', $journal->id, $search));