Skip to content

Firefly III: a personal finances manager

Changed trigger constructor. No longer needs model AND journal, now only model. Wait for it...

James Cole12b6791e8b2d
diff --git a/app/Rules/Processor.php b/app/Rules/Processor.php
index 05022e9ec2..64431de106 100644
--- a/app/Rules/Processor.php
+++ b/app/Rules/Processor.php
@@ -112,9 +112,9 @@ class Processor
foreach ($this->triggers as $trigger) {
$foundTriggers++;
- /** @var TriggerInterface $triggerClass */
- $triggerClass = TriggerFactory::getTrigger($trigger, $this->journal);
- if ($triggerClass->triggered()) {
+ /** @var TriggerInterface $triggerObject */
+ $triggerObject = TriggerFactory::getTrigger($trigger);
+ if ($triggerObject->triggered()) {
$hitTriggers++;
}
if ($trigger->stop_processing) {
diff --git a/app/Rules/Triggers/AmountExactly.php b/app/Rules/Triggers/AmountExactly.php
index 2ea3afdc3a..b07b8a5368 100644
--- a/app/Rules/Triggers/AmountExactly.php
+++ b/app/Rules/Triggers/AmountExactly.php
@@ -22,21 +22,19 @@ use Log;
*/
class AmountExactly implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
+
}
/**
@@ -65,11 +63,13 @@ class AmountExactly implements TriggerInterface
}
/**
+ * @param TransactionJournal $journal
+ *
* @return bool
*/
- public function triggered()
+ public function triggered(TransactionJournal $journal)
{
- $amount = $this->journal->amount_positive;
+ $amount = $journal->amount_positive;
$compare = $this->trigger->trigger_value;
$result = bccomp($amount, $compare, 4);
if ($result === 0) {
diff --git a/app/Rules/Triggers/AmountLess.php b/app/Rules/Triggers/AmountLess.php
index 991d6365a3..87271fdd9f 100644
--- a/app/Rules/Triggers/AmountLess.php
+++ b/app/Rules/Triggers/AmountLess.php
@@ -22,21 +22,20 @@ use Log;
*/
class AmountLess implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
+
}
/**
@@ -65,11 +64,13 @@ class AmountLess implements TriggerInterface
}
/**
+ * @param TransactionJournal $journal
+ *
* @return bool
*/
- public function triggered()
+ public function triggered(TransactionJournal $journal)
{
- $amount = $this->journal->amount_positive;
+ $amount = $journal->amount_positive;
$compare = $this->trigger->trigger_value;
$result = bccomp($amount, $compare, 4);
if ($result === -1) {
diff --git a/app/Rules/Triggers/AmountMore.php b/app/Rules/Triggers/AmountMore.php
index 104d0363ef..6e17ff8d68 100644
--- a/app/Rules/Triggers/AmountMore.php
+++ b/app/Rules/Triggers/AmountMore.php
@@ -22,21 +22,20 @@ use Log;
*/
class AmountMore implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
+
}
/**
@@ -65,11 +64,13 @@ class AmountMore implements TriggerInterface
}
/**
+ * @param TransactionJournal $journal
+ *
* @return bool
*/
- public function triggered()
+ public function triggered(TransactionJournal $journal)
{
- $amount = $this->journal->amount_positive;
+ $amount = $journal->amount_positive;
$compare = $this->trigger->trigger_value;
$result = bccomp($amount, $compare, 4);
if ($result === 1) {
diff --git a/app/Rules/Triggers/DescriptionContains.php b/app/Rules/Triggers/DescriptionContains.php
index 0d760016c9..e88dd97324 100644
--- a/app/Rules/Triggers/DescriptionContains.php
+++ b/app/Rules/Triggers/DescriptionContains.php
@@ -22,21 +22,20 @@ use Log;
*/
class DescriptionContains implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
+
}
/**
@@ -65,12 +64,14 @@ class DescriptionContains implements TriggerInterface
}
/**
+ * @param TransactionJournal $journal
+ *
* @return bool
*/
- public function triggered()
+ public function triggered(TransactionJournal $journal)
{
$search = strtolower($this->trigger->trigger_value);
- $source = strtolower($this->journal->description);
+ $source = strtolower($journal->description);
$strpos = strpos($source, $search);
if (!($strpos === false)) {
diff --git a/app/Rules/Triggers/DescriptionEnds.php b/app/Rules/Triggers/DescriptionEnds.php
index 951cf8d7e1..2b419415e7 100644
--- a/app/Rules/Triggers/DescriptionEnds.php
+++ b/app/Rules/Triggers/DescriptionEnds.php
@@ -21,21 +21,20 @@ use Log;
*/
class DescriptionEnds implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
+
}
/**
@@ -64,11 +63,13 @@ class DescriptionEnds implements TriggerInterface
}
/**
+ * @param TransactionJournal $journal
+ *
* @return bool
*/
- public function triggered()
+ public function triggered(TransactionJournal $journal)
{
- $description = strtolower($this->journal->description);
+ $description = strtolower($journal->description);
$descriptionLength = strlen($description);
$search = strtolower($this->trigger->trigger_value);
$searchLength = strlen($search);
diff --git a/app/Rules/Triggers/DescriptionIs.php b/app/Rules/Triggers/DescriptionIs.php
index 713aaa8fc8..95b8a134ae 100644
--- a/app/Rules/Triggers/DescriptionIs.php
+++ b/app/Rules/Triggers/DescriptionIs.php
@@ -21,39 +21,19 @@ use Log;
*/
class DescriptionIs implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
- }
-
- /**
- * @return bool
- */
- public function triggered()
- {
- $description = strtolower($this->journal->description);
- $search = strtolower($this->trigger->trigger_value);
-
- if ($description == $search) {
- Log::debug('"' . $description . '" equals "' . $search . '" exactly. Return true.');
-
- return true;
- }
- Log::debug('"' . $description . '" does not equal "' . $search . '". Return false.');
-
- return false;
}
@@ -81,4 +61,25 @@ class DescriptionIs implements TriggerInterface
return true;
}
+
+ /**
+ * @param TransactionJournal $journal
+ *
+ * @return bool
+ */
+ public function triggered(TransactionJournal $journal)
+ {
+ $description = strtolower($journal->description);
+ $search = strtolower($this->trigger->trigger_value);
+
+ if ($description == $search) {
+ Log::debug('"' . $description . '" equals "' . $search . '" exactly. Return true.');
+
+ return true;
+ }
+ Log::debug('"' . $description . '" does not equal "' . $search . '". Return false.');
+
+ return false;
+
+ }
}
diff --git a/app/Rules/Triggers/DescriptionStarts.php b/app/Rules/Triggers/DescriptionStarts.php
index a9cc27a44a..5f8386a402 100644
--- a/app/Rules/Triggers/DescriptionStarts.php
+++ b/app/Rules/Triggers/DescriptionStarts.php
@@ -21,41 +21,19 @@ use Log;
*/
class DescriptionStarts implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
- }
-
- /**
- * @return bool
- */
- public function triggered()
- {
- $description = strtolower($this->journal->description);
- $search = strtolower($this->trigger->trigger_value);
-
- $part = substr($description, 0, strlen($search));
-
- if ($part == $search) {
- Log::debug('"' . $description . '" starts with "' . $search . '". Return true.');
-
- return true;
- }
- Log::debug('"' . $description . '" does not start with "' . $search . '". Return false.');
-
- return false;
}
@@ -83,4 +61,27 @@ class DescriptionStarts implements TriggerInterface
return true;
}
+
+ /**
+ * @param TransactionJournal $journal
+ *
+ * @return bool
+ */
+ public function triggered(TransactionJournal $journal)
+ {
+ $description = strtolower($journal->description);
+ $search = strtolower($this->trigger->trigger_value);
+
+ $part = substr($description, 0, strlen($search));
+
+ if ($part == $search) {
+ Log::debug('"' . $description . '" starts with "' . $search . '". Return true.');
+
+ return true;
+ }
+ Log::debug('"' . $description . '" does not start with "' . $search . '". Return false.');
+
+ return false;
+
+ }
}
diff --git a/app/Rules/Triggers/FromAccountContains.php b/app/Rules/Triggers/FromAccountContains.php
index 8e600b4d95..5b6988fa61 100644
--- a/app/Rules/Triggers/FromAccountContains.php
+++ b/app/Rules/Triggers/FromAccountContains.php
@@ -21,43 +21,19 @@ use Log;
*/
class FromAccountContains implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
- }
-
- /**
- * @return bool
- */
- public function triggered()
- {
- $fromAccountName = strtolower($this->journal->source_account->name);
- $search = strtolower($this->trigger->trigger_value);
- $strpos = strpos($fromAccountName, $search);
-
- if (!($strpos === false)) {
- // found something
- Log::debug('"' . $fromAccountName . '" contains the text "' . $search . '". Return true.');
-
- return true;
- }
-
- // found nothing.
- Log::debug('"' . $fromAccountName . '" does not contain the text "' . $search . '". Return false.');
-
- return false;
}
@@ -85,4 +61,29 @@ class FromAccountContains implements TriggerInterface
return true;
}
+
+ /**
+ * @param TransactionJournal $journal
+ *
+ * @return bool
+ */
+ public function triggered(TransactionJournal $journal)
+ {
+ $fromAccountName = strtolower($journal->source_account->name);
+ $search = strtolower($this->trigger->trigger_value);
+ $strpos = strpos($fromAccountName, $search);
+
+ if (!($strpos === false)) {
+ // found something
+ Log::debug('"' . $fromAccountName . '" contains the text "' . $search . '". Return true.');
+
+ return true;
+ }
+
+ // found nothing.
+ Log::debug('"' . $fromAccountName . '" does not contain the text "' . $search . '". Return false.');
+
+ return false;
+
+ }
}
diff --git a/app/Rules/Triggers/FromAccountEnds.php b/app/Rules/Triggers/FromAccountEnds.php
index 0c49e371e8..a6ef9bd98e 100644
--- a/app/Rules/Triggers/FromAccountEnds.php
+++ b/app/Rules/Triggers/FromAccountEnds.php
@@ -21,29 +21,55 @@ use Log;
*/
class FromAccountEnds implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
+
+ }
+
+ /**
+ * A trigger is said to "match anything", or match any given transaction,
+ * when the trigger value is very vague or has no restrictions. Easy examples
+ * are the "AmountMore"-trigger combined with an amount of 0: any given transaction
+ * has an amount of more than zero! Other examples are all the "Description"-triggers
+ * which have hard time handling empty trigger values such as "" or "*" (wild cards).
+ *
+ * If the user tries to create such a trigger, this method MUST return true so Firefly III
+ * can stop the storing / updating the trigger. If the trigger is in any way restrictive
+ * (even if it will still include 99.9% of the users transactions), this method MUST return
+ * false.
+ *
+ * @param null $value
+ *
+ * @return bool
+ */
+ public static function willMatchEverything($value = null)
+ {
+ if (!is_null($value)) {
+ return strval($value) === "";
+ }
+
+ return true;
}
/**
+ * @param TransactionJournal $journal
+ *
* @return bool
*/
- public function triggered()
+ public function triggered(TransactionJournal $journal)
{
- $name = strtolower($this->journal->source_account->name);
+ $name = strtolower($journal->source_account->name);
$nameLength = strlen($name);
$search = strtolower($this->trigger->trigger_value);
$searchLength = strlen($search);
@@ -70,29 +96,4 @@ class FromAccountEnds implements TriggerInterface
return false;
}
-
- /**
- * A trigger is said to "match anything", or match any given transaction,
- * when the trigger value is very vague or has no restrictions. Easy examples
- * are the "AmountMore"-trigger combined with an amount of 0: any given transaction
- * has an amount of more than zero! Other examples are all the "Description"-triggers
- * which have hard time handling empty trigger values such as "" or "*" (wild cards).
- *
- * If the user tries to create such a trigger, this method MUST return true so Firefly III
- * can stop the storing / updating the trigger. If the trigger is in any way restrictive
- * (even if it will still include 99.9% of the users transactions), this method MUST return
- * false.
- *
- * @param null $value
- *
- * @return bool
- */
- public static function willMatchEverything($value = null)
- {
- if (!is_null($value)) {
- return strval($value) === "";
- }
-
- return true;
- }
}
diff --git a/app/Rules/Triggers/FromAccountIs.php b/app/Rules/Triggers/FromAccountIs.php
index 322890b90e..3105a70150 100644
--- a/app/Rules/Triggers/FromAccountIs.php
+++ b/app/Rules/Triggers/FromAccountIs.php
@@ -21,21 +21,20 @@ use Log;
*/
class FromAccountIs implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
+
}
/**
@@ -64,11 +63,13 @@ class FromAccountIs implements TriggerInterface
}
/**
+ * @param TransactionJournal $journal
+ *
* @return bool
*/
- public function triggered()
+ public function triggered(TransactionJournal $journal)
{
- $fromAccountName = strtolower($this->journal->source_account->name);
+ $fromAccountName = strtolower($journal->source_account->name);
$search = strtolower($this->trigger->trigger_value);
if ($fromAccountName == $search) {
diff --git a/app/Rules/Triggers/FromAccountStarts.php b/app/Rules/Triggers/FromAccountStarts.php
index e4b94aa896..a627f7a843 100644
--- a/app/Rules/Triggers/FromAccountStarts.php
+++ b/app/Rules/Triggers/FromAccountStarts.php
@@ -21,21 +21,20 @@ use Log;
*/
class FromAccountStarts implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
+
}
/**
@@ -64,11 +63,13 @@ class FromAccountStarts implements TriggerInterface
}
/**
+ * @param TransactionJournal $journal
+ *
* @return bool
*/
- public function triggered()
+ public function triggered(TransactionJournal $journal)
{
- $fromAccountName = strtolower($this->journal->source_account->name);
+ $fromAccountName = strtolower($journal->source_account->name);
$search = strtolower($this->trigger->trigger_value);
$part = substr($fromAccountName, 0, strlen($search));
diff --git a/app/Rules/Triggers/ToAccountContains.php b/app/Rules/Triggers/ToAccountContains.php
index 0f823d453f..cdbcb0b26e 100644
--- a/app/Rules/Triggers/ToAccountContains.php
+++ b/app/Rules/Triggers/ToAccountContains.php
@@ -21,47 +21,22 @@ use Log;
*/
class ToAccountContains implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
- }
-
- /**
- * @return bool
- */
- public function triggered()
- {
- $toAccountName = strtolower($this->journal->destination_account->name);
- $search = strtolower($this->trigger->trigger_value);
- $strpos = strpos($toAccountName, $search);
-
- if (!($strpos === false)) {
- // found something
- Log::debug('"' . $toAccountName . '" contains the text "' . $search . '". Return true.');
-
- return true;
- }
-
- // found nothing.
- Log::debug('"' . $toAccountName . '" does not contain the text "' . $search . '". Return false.');
-
- return false;
}
-
/**
* A trigger is said to "match anything", or match any given transaction,
* when the trigger value is very vague or has no restrictions. Easy examples
@@ -86,4 +61,29 @@ class ToAccountContains implements TriggerInterface
return true;
}
+
+ /**
+ * @param TransactionJournal $journal
+ *
+ * @return bool
+ */
+ public function triggered(TransactionJournal $journal)
+ {
+ $toAccountName = strtolower($journal->destination_account->name);
+ $search = strtolower($this->trigger->trigger_value);
+ $strpos = strpos($toAccountName, $search);
+
+ if (!($strpos === false)) {
+ // found something
+ Log::debug('"' . $toAccountName . '" contains the text "' . $search . '". Return true.');
+
+ return true;
+ }
+
+ // found nothing.
+ Log::debug('"' . $toAccountName . '" does not contain the text "' . $search . '". Return false.');
+
+ return false;
+
+ }
}
diff --git a/app/Rules/Triggers/ToAccountEnds.php b/app/Rules/Triggers/ToAccountEnds.php
index 3542b0594c..0f3046f7eb 100644
--- a/app/Rules/Triggers/ToAccountEnds.php
+++ b/app/Rules/Triggers/ToAccountEnds.php
@@ -21,29 +21,55 @@ use Log;
*/
class ToAccountEnds implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
+
+ }
+
+ /**
+ * A trigger is said to "match anything", or match any given transaction,
+ * when the trigger value is very vague or has no restrictions. Easy examples
+ * are the "AmountMore"-trigger combined with an amount of 0: any given transaction
+ * has an amount of more than zero! Other examples are all the "Description"-triggers
+ * which have hard time handling empty trigger values such as "" or "*" (wild cards).
+ *
+ * If the user tries to create such a trigger, this method MUST return true so Firefly III
+ * can stop the storing / updating the trigger. If the trigger is in any way restrictive
+ * (even if it will still include 99.9% of the users transactions), this method MUST return
+ * false.
+ *
+ * @param null $value
+ *
+ * @return bool
+ */
+ public static function willMatchEverything($value = null)
+ {
+ if (!is_null($value)) {
+ return strval($value) === "";
+ }
+
+ return true;
}
/**
+ * @param TransactionJournal $journal
+ *
* @return bool
*/
- public function triggered()
+ public function triggered(TransactionJournal $journal)
{
- $toAccountName = strtolower($this->journal->destination_account->name);
+ $toAccountName = strtolower($journal->destination_account->name);
$toAccountNameLength = strlen($toAccountName);
$search = strtolower($this->trigger->trigger_value);
$searchLength = strlen($search);
@@ -70,29 +96,4 @@ class ToAccountEnds implements TriggerInterface
return false;
}
-
- /**
- * A trigger is said to "match anything", or match any given transaction,
- * when the trigger value is very vague or has no restrictions. Easy examples
- * are the "AmountMore"-trigger combined with an amount of 0: any given transaction
- * has an amount of more than zero! Other examples are all the "Description"-triggers
- * which have hard time handling empty trigger values such as "" or "*" (wild cards).
- *
- * If the user tries to create such a trigger, this method MUST return true so Firefly III
- * can stop the storing / updating the trigger. If the trigger is in any way restrictive
- * (even if it will still include 99.9% of the users transactions), this method MUST return
- * false.
- *
- * @param null $value
- *
- * @return bool
- */
- public static function willMatchEverything($value = null)
- {
- if (!is_null($value)) {
- return strval($value) === "";
- }
-
- return true;
- }
}
diff --git a/app/Rules/Triggers/ToAccountIs.php b/app/Rules/Triggers/ToAccountIs.php
index 7034d19072..cee32af66d 100644
--- a/app/Rules/Triggers/ToAccountIs.php
+++ b/app/Rules/Triggers/ToAccountIs.php
@@ -21,39 +21,19 @@ use Log;
*/
class ToAccountIs implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
- }
-
- /**
- * @return bool
- */
- public function triggered()
- {
- $toAccountName = strtolower($this->journal->destination_account->name);
- $search = strtolower($this->trigger->trigger_value);
-
- if ($toAccountName == $search) {
- Log::debug('"' . $toAccountName . '" equals "' . $search . '" exactly. Return true.');
-
- return true;
- }
- Log::debug('"' . $toAccountName . '" does not equal "' . $search . '". Return false.');
-
- return false;
}
@@ -81,4 +61,25 @@ class ToAccountIs implements TriggerInterface
return true;
}
+
+ /**
+ * @param TransactionJournal $journal
+ *
+ * @return bool
+ */
+ public function triggered(TransactionJournal $journal)
+ {
+ $toAccountName = strtolower($journal->destination_account->name);
+ $search = strtolower($this->trigger->trigger_value);
+
+ if ($toAccountName == $search) {
+ Log::debug('"' . $toAccountName . '" equals "' . $search . '" exactly. Return true.');
+
+ return true;
+ }
+ Log::debug('"' . $toAccountName . '" does not equal "' . $search . '". Return false.');
+
+ return false;
+
+ }
}
diff --git a/app/Rules/Triggers/ToAccountStarts.php b/app/Rules/Triggers/ToAccountStarts.php
index 57242382ce..6c9b1d876c 100644
--- a/app/Rules/Triggers/ToAccountStarts.php
+++ b/app/Rules/Triggers/ToAccountStarts.php
@@ -21,41 +21,19 @@ use Log;
*/
class ToAccountStarts implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
- }
-
- /**
- * @return bool
- */
- public function triggered()
- {
- $toAccountName = strtolower($this->journal->destination_account->name);
- $search = strtolower($this->trigger->trigger_value);
-
- $part = substr($toAccountName, 0, strlen($search));
-
- if ($part == $search) {
- Log::debug('"' . $toAccountName . '" starts with "' . $search . '". Return true.');
-
- return true;
- }
- Log::debug('"' . $toAccountName . '" does not start with "' . $search . '". Return false.');
-
- return false;
}
@@ -83,4 +61,27 @@ class ToAccountStarts implements TriggerInterface
return true;
}
+
+ /**
+ * @param TransactionJournal $journal
+ *
+ * @return bool
+ */
+ public function triggered(TransactionJournal $journal)
+ {
+ $toAccountName = strtolower($journal->destination_account->name);
+ $search = strtolower($this->trigger->trigger_value);
+
+ $part = substr($toAccountName, 0, strlen($search));
+
+ if ($part == $search) {
+ Log::debug('"' . $toAccountName . '" starts with "' . $search . '". Return true.');
+
+ return true;
+ }
+ Log::debug('"' . $toAccountName . '" does not start with "' . $search . '". Return false.');
+
+ return false;
+
+ }
}
diff --git a/app/Rules/Triggers/TransactionType.php b/app/Rules/Triggers/TransactionType.php
index 2573a0ef96..3ff4ed9b68 100644
--- a/app/Rules/Triggers/TransactionType.php
+++ b/app/Rules/Triggers/TransactionType.php
@@ -21,39 +21,20 @@ use Log;
*/
class TransactionType implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
- }
-
- /**
- * @return bool
- */
- public function triggered()
- {
- $type = strtolower($this->journal->transactionType->type);
- $search = strtolower($this->trigger->trigger_value);
- if ($type == $search) {
- Log::debug('Journal is of type "' . $type . '" which matches with "' . $search . '". Return true');
-
- return true;
- }
- Log::debug('Journal is of type "' . $type . '" which does not match with "' . $search . '". Return false');
-
- return false;
}
/**
@@ -80,4 +61,24 @@ class TransactionType implements TriggerInterface
return true;
}
+
+ /**
+ * @param TransactionJournal $journal
+ *
+ * @return bool
+ */
+ public function triggered(TransactionJournal $journal)
+ {
+ $type = strtolower($journal->transactionType->type);
+ $search = strtolower($this->trigger->trigger_value);
+
+ if ($type == $search) {
+ Log::debug('Journal is of type "' . $type . '" which matches with "' . $search . '". Return true');
+
+ return true;
+ }
+ Log::debug('Journal is of type "' . $type . '" which does not match with "' . $search . '". Return false');
+
+ return false;
+ }
}
diff --git a/app/Rules/Triggers/TriggerFactory.php b/app/Rules/Triggers/TriggerFactory.php
index 2eaf47e354..d189be1e62 100644
--- a/app/Rules/Triggers/TriggerFactory.php
+++ b/app/Rules/Triggers/TriggerFactory.php
@@ -12,7 +12,6 @@ namespace FireflyIII\Rules\Triggers;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\RuleTrigger;
-use FireflyIII\Models\TransactionJournal;
use FireflyIII\Support\Domain;
/**
@@ -27,17 +26,16 @@ class TriggerFactory
/**
* Returns the trigger for the given type and journal
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*
* @return TriggerInterface
*/
- public static function getTrigger(RuleTrigger $trigger, TransactionJournal $journal): TriggerInterface
+ public static function getTrigger(RuleTrigger $trigger): TriggerInterface
{
$triggerType = $trigger->trigger_type;
$class = self::getTriggerClass($triggerType);
- return new $class($trigger, $journal);
+ return new $class($trigger);
}
/**
@@ -45,7 +43,8 @@ class TriggerFactory
*
* @param string $triggerType
*
- * @return TriggerInterface
+ * @return TriggerInterface|string
+ * @throws FireflyException
*/
public static function getTriggerClass(string $triggerType): string
{
diff --git a/app/Rules/Triggers/TriggerInterface.php b/app/Rules/Triggers/TriggerInterface.php
index 1fa4c77ac2..fc96207354 100644
--- a/app/Rules/Triggers/TriggerInterface.php
+++ b/app/Rules/Triggers/TriggerInterface.php
@@ -23,10 +23,9 @@ interface TriggerInterface
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal);
+ public function __construct(RuleTrigger $trigger);
/**
* A trigger is said to "match anything", or match any given transaction,
@@ -47,7 +46,9 @@ interface TriggerInterface
public static function willMatchEverything($value = null);
/**
+ * @param TransactionJournal $journal
+ *
* @return bool
*/
- public function triggered();
+ public function triggered(TransactionJournal $journal);
}
diff --git a/app/Rules/Triggers/UserAction.php b/app/Rules/Triggers/UserAction.php
index f9e2046dfe..e03d7d1ee8 100644
--- a/app/Rules/Triggers/UserAction.php
+++ b/app/Rules/Triggers/UserAction.php
@@ -21,21 +21,20 @@ use Log;
*/
class UserAction implements TriggerInterface
{
- /** @var TransactionJournal */
- protected $journal;
+
+
/** @var RuleTrigger */
protected $trigger;
/**
* TriggerInterface constructor.
*
- * @param RuleTrigger $trigger
- * @param TransactionJournal $journal
+ * @param RuleTrigger $trigger
*/
- public function __construct(RuleTrigger $trigger, TransactionJournal $journal)
+ public function __construct(RuleTrigger $trigger)
{
$this->trigger = $trigger;
- $this->journal = $journal;
+
}
@@ -63,9 +62,11 @@ class UserAction implements TriggerInterface
/**
* This trigger is always triggered, because the rule that it is a part of has been pre-selected on this condition.
*
+ * @param TransactionJournal $journal
+ *
* @return bool
*/
- public function triggered()
+ public function triggered(TransactionJournal $journal)
{
Log::debug('user_action always returns true.');