Code clean up.

This commit is contained in:
James Cole
2016-02-17 18:23:20 +01:00
parent ddfbd69e8b
commit cd057045e6

View File

@@ -14,10 +14,10 @@ use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleAction;
use FireflyIII\Models\RuleTrigger; use FireflyIII\Models\RuleTrigger;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Rules\Actions\ActionInterface;
use FireflyIII\Rules\Actions\ActionFactory; use FireflyIII\Rules\Actions\ActionFactory;
use FireflyIII\Rules\Triggers\TriggerInterface; use FireflyIII\Rules\Actions\ActionInterface;
use FireflyIII\Rules\Triggers\TriggerFactory; use FireflyIII\Rules\Triggers\TriggerFactory;
use FireflyIII\Rules\Triggers\TriggerInterface;
use Log; use Log;
/** /**
@@ -40,8 +40,8 @@ class Processor
*/ */
public function __construct(Rule $rule, TransactionJournal $journal) public function __construct(Rule $rule, TransactionJournal $journal)
{ {
$this->rule = $rule; $this->rule = $rule;
$this->journal = $journal; $this->journal = $journal;
} }
/** /**
@@ -89,20 +89,24 @@ class Processor
/** /**
* Checks whether the current transaction is triggered by the current rule * Checks whether the current transaction is triggered by the current rule
*
* @return boolean * @return boolean
*/ */
public function isTriggered() { public function isTriggered()
{
return $this->triggered(); return $this->triggered();
} }
/** /**
* Checks whether the current transaction is triggered by the list of given triggers * Checks whether the current transaction is triggered by the list of given triggers
*
* @return boolean * @return boolean
*/ */
public function isTriggeredBy(array $triggers) { public function isTriggeredBy(array $triggers)
{
return $this->triggeredBy($triggers); return $this->triggeredBy($triggers);
} }
/** /**
* @return bool * @return bool
*/ */
@@ -125,18 +129,30 @@ class Processor
return true; return true;
} }
/**
* Checks whether the current transaction is triggered by the current rule
*
* @return bool
*/
protected function triggered()
{
return $this->triggeredBy($this->rule->ruleTriggers()->orderBy('order', 'ASC')->get());
}
/** /**
* Method to check whether the current transaction would be triggered * Method to check whether the current transaction would be triggered
* by the given list of triggers * by the given list of triggers
*
* @return bool * @return bool
*/ */
protected function triggeredBy($triggers) { protected function triggeredBy($triggers)
{
$foundTriggers = 0; $foundTriggers = 0;
$hitTriggers = 0; $hitTriggers = 0;
/** @var RuleTrigger $trigger */ /** @var RuleTrigger $trigger */
foreach ($triggers as $trigger) { foreach ($triggers as $trigger) {
$foundTriggers++; $foundTriggers++;
/** @var TriggerInterface $triggerClass */ /** @var TriggerInterface $triggerClass */
$triggerClass = TriggerFactory::getTrigger($trigger, $this->journal); $triggerClass = TriggerFactory::getTrigger($trigger, $this->journal);
if ($triggerClass->triggered()) { if ($triggerClass->triggered()) {
@@ -150,15 +166,7 @@ class Processor
Log::debug('Total: ' . $foundTriggers . ' found triggers. ' . $hitTriggers . ' triggers were hit.'); Log::debug('Total: ' . $foundTriggers . ' found triggers. ' . $hitTriggers . ' triggers were hit.');
return ($hitTriggers == $foundTriggers); return ($hitTriggers == $foundTriggers);
}
/**
* Checks whether the current transaction is triggered by the current rule
* @return bool
*/
protected function triggered()
{
return $this->triggeredBy($this->rule->ruleTriggers()->orderBy('order', 'ASC')->get());
} }