Skip to content

Firefly III: a personal finances manager

Fix factory and triggers.

James Cole51acc34a80c8
diff --git a/app/Rules/Triggers/AbstractTrigger.php b/app/Rules/Triggers/AbstractTrigger.php
index 62f1cc48bf..5263073946 100644
--- a/app/Rules/Triggers/AbstractTrigger.php
+++ b/app/Rules/Triggers/AbstractTrigger.php
@@ -71,7 +71,7 @@ class AbstractTrigger
*/
public static function makeFromTriggerValue(string $triggerValue)
{
- $self = new self;
+ $self = new static;
$self->triggerValue = $triggerValue;
return $self;
diff --git a/app/Rules/Triggers/AmountExactly.php b/app/Rules/Triggers/AmountExactly.php
index e9af2cd146..0ce48cc86a 100644
--- a/app/Rules/Triggers/AmountExactly.php
+++ b/app/Rules/Triggers/AmountExactly.php
@@ -55,7 +55,7 @@ class AmountExactly extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$amount = $journal->amount_positive;
- $compare = $this->trigger->trigger_value;
+ $compare = $this->triggerValue;
$result = bccomp($amount, $compare, 4);
if ($result === 0) {
// found something
diff --git a/app/Rules/Triggers/AmountLess.php b/app/Rules/Triggers/AmountLess.php
index fdacdab19c..d98fcdf9c3 100644
--- a/app/Rules/Triggers/AmountLess.php
+++ b/app/Rules/Triggers/AmountLess.php
@@ -55,7 +55,7 @@ class AmountLess extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$amount = $journal->amount_positive;
- $compare = $this->trigger->trigger_value;
+ $compare = $this->triggerValue;
$result = bccomp($amount, $compare, 4);
if ($result === -1) {
// found something
diff --git a/app/Rules/Triggers/AmountMore.php b/app/Rules/Triggers/AmountMore.php
index 82354fec7e..543de53062 100644
--- a/app/Rules/Triggers/AmountMore.php
+++ b/app/Rules/Triggers/AmountMore.php
@@ -55,7 +55,7 @@ class AmountMore extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$amount = $journal->amount_positive;
- $compare = $this->trigger->trigger_value;
+ $compare = $this->triggerValue;
$result = bccomp($amount, $compare, 4);
if ($result === 1) {
// found something
diff --git a/app/Rules/Triggers/DescriptionContains.php b/app/Rules/Triggers/DescriptionContains.php
index b399bb8011..093ed9fd72 100644
--- a/app/Rules/Triggers/DescriptionContains.php
+++ b/app/Rules/Triggers/DescriptionContains.php
@@ -54,7 +54,7 @@ class DescriptionContains extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal)
{
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
$source = strtolower($journal->description);
$strpos = strpos($source, $search);
diff --git a/app/Rules/Triggers/DescriptionEnds.php b/app/Rules/Triggers/DescriptionEnds.php
index 6d4510f782..a9059e43a9 100644
--- a/app/Rules/Triggers/DescriptionEnds.php
+++ b/app/Rules/Triggers/DescriptionEnds.php
@@ -55,7 +55,7 @@ class DescriptionEnds extends AbstractTrigger implements TriggerInterface
{
$description = strtolower($journal->description);
$descriptionLength = strlen($description);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
$searchLength = strlen($search);
// if the string to search for is longer than the description,
diff --git a/app/Rules/Triggers/DescriptionIs.php b/app/Rules/Triggers/DescriptionIs.php
index d2b1c0ef54..764c0c1c58 100644
--- a/app/Rules/Triggers/DescriptionIs.php
+++ b/app/Rules/Triggers/DescriptionIs.php
@@ -54,7 +54,7 @@ class DescriptionIs extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$description = strtolower($journal->description);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
if ($description == $search) {
Log::debug('"' . $description . '" equals "' . $search . '" exactly. Return true.');
diff --git a/app/Rules/Triggers/DescriptionStarts.php b/app/Rules/Triggers/DescriptionStarts.php
index 03ce8a98da..7379fd0e2a 100644
--- a/app/Rules/Triggers/DescriptionStarts.php
+++ b/app/Rules/Triggers/DescriptionStarts.php
@@ -54,7 +54,7 @@ class DescriptionStarts extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$description = strtolower($journal->description);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
$part = substr($description, 0, strlen($search));
diff --git a/app/Rules/Triggers/FromAccountContains.php b/app/Rules/Triggers/FromAccountContains.php
index 67b9f1fadc..c8ef44a4e5 100644
--- a/app/Rules/Triggers/FromAccountContains.php
+++ b/app/Rules/Triggers/FromAccountContains.php
@@ -54,7 +54,7 @@ class FromAccountContains extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$fromAccountName = strtolower($journal->source_account->name);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
$strpos = strpos($fromAccountName, $search);
if (!($strpos === false)) {
diff --git a/app/Rules/Triggers/FromAccountEnds.php b/app/Rules/Triggers/FromAccountEnds.php
index e20380984c..01958bb928 100644
--- a/app/Rules/Triggers/FromAccountEnds.php
+++ b/app/Rules/Triggers/FromAccountEnds.php
@@ -55,7 +55,7 @@ class FromAccountEnds extends AbstractTrigger implements TriggerInterface
{
$name = strtolower($journal->source_account->name);
$nameLength = strlen($name);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
$searchLength = strlen($search);
// if the string to search for is longer than the account name,
diff --git a/app/Rules/Triggers/FromAccountIs.php b/app/Rules/Triggers/FromAccountIs.php
index fe07b4188b..1257d62a32 100644
--- a/app/Rules/Triggers/FromAccountIs.php
+++ b/app/Rules/Triggers/FromAccountIs.php
@@ -54,7 +54,7 @@ class FromAccountIs extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$fromAccountName = strtolower($journal->source_account->name);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
if ($fromAccountName == $search) {
Log::debug('"' . $fromAccountName . '" equals "' . $search . '" exactly. Return true.');
diff --git a/app/Rules/Triggers/FromAccountStarts.php b/app/Rules/Triggers/FromAccountStarts.php
index c7d2560dcd..b2b8439b96 100644
--- a/app/Rules/Triggers/FromAccountStarts.php
+++ b/app/Rules/Triggers/FromAccountStarts.php
@@ -54,7 +54,7 @@ class FromAccountStarts extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$fromAccountName = strtolower($journal->source_account->name);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
$part = substr($fromAccountName, 0, strlen($search));
diff --git a/app/Rules/Triggers/ToAccountContains.php b/app/Rules/Triggers/ToAccountContains.php
index ad15ede899..da798084df 100644
--- a/app/Rules/Triggers/ToAccountContains.php
+++ b/app/Rules/Triggers/ToAccountContains.php
@@ -54,7 +54,7 @@ class ToAccountContains extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$toAccountName = strtolower($journal->destination_account->name);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
$strpos = strpos($toAccountName, $search);
if (!($strpos === false)) {
diff --git a/app/Rules/Triggers/ToAccountEnds.php b/app/Rules/Triggers/ToAccountEnds.php
index 17f54d219d..d065868ac4 100644
--- a/app/Rules/Triggers/ToAccountEnds.php
+++ b/app/Rules/Triggers/ToAccountEnds.php
@@ -55,7 +55,7 @@ class ToAccountEnds extends AbstractTrigger implements TriggerInterface
{
$toAccountName = strtolower($journal->destination_account->name);
$toAccountNameLength = strlen($toAccountName);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
$searchLength = strlen($search);
// if the string to search for is longer than the account name,
diff --git a/app/Rules/Triggers/ToAccountIs.php b/app/Rules/Triggers/ToAccountIs.php
index 9791ba2cba..942264c877 100644
--- a/app/Rules/Triggers/ToAccountIs.php
+++ b/app/Rules/Triggers/ToAccountIs.php
@@ -54,7 +54,7 @@ class ToAccountIs extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$toAccountName = strtolower($journal->destination_account->name);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
if ($toAccountName == $search) {
Log::debug('"' . $toAccountName . '" equals "' . $search . '" exactly. Return true.');
diff --git a/app/Rules/Triggers/ToAccountStarts.php b/app/Rules/Triggers/ToAccountStarts.php
index 09bc6d0ac7..58bceb1e4d 100644
--- a/app/Rules/Triggers/ToAccountStarts.php
+++ b/app/Rules/Triggers/ToAccountStarts.php
@@ -54,7 +54,7 @@ class ToAccountStarts extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$toAccountName = strtolower($journal->destination_account->name);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
$part = substr($toAccountName, 0, strlen($search));
diff --git a/app/Rules/Triggers/TransactionType.php b/app/Rules/Triggers/TransactionType.php
index 4c3e2c0ea5..204cacdcc4 100644
--- a/app/Rules/Triggers/TransactionType.php
+++ b/app/Rules/Triggers/TransactionType.php
@@ -54,7 +54,7 @@ class TransactionType extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal)
{
$type = strtolower($journal->transactionType->type);
- $search = strtolower($this->trigger->trigger_value);
+ $search = strtolower($this->triggerValue);
if ($type == $search) {
Log::debug('Journal is of type "' . $type . '" which matches with "' . $search . '". Return true');
diff --git a/app/Rules/Triggers/TriggerFactory.php b/app/Rules/Triggers/TriggerFactory.php
index d189be1e62..01d19963d9 100644
--- a/app/Rules/Triggers/TriggerFactory.php
+++ b/app/Rules/Triggers/TriggerFactory.php
@@ -28,14 +28,17 @@ class TriggerFactory
*
* @param RuleTrigger $trigger
*
- * @return TriggerInterface
+ * @return AbstractTrigger
*/
- public static function getTrigger(RuleTrigger $trigger): TriggerInterface
+ public static function getTrigger(RuleTrigger $trigger)
{
$triggerType = $trigger->trigger_type;
- $class = self::getTriggerClass($triggerType);
- return new $class($trigger);
+ /** @var AbstractTrigger $class */
+ $class = self::getTriggerClass($triggerType);
+ $obj = $class::makeFromTriggerValue($trigger->trigger_value);
+
+ return $obj;
}
/**