Skip to content

Firefly III: a personal finances manager

Remove matchesAnything

James Cole28fa1264b787
diff --git a/app/Models/RuleTrigger.php b/app/Models/RuleTrigger.php
index 365e873722..47a3d9edc0 100644
--- a/app/Models/RuleTrigger.php
+++ b/app/Models/RuleTrigger.php
@@ -30,15 +30,6 @@ use Illuminate\Database\Eloquent\Model;
*/
class RuleTrigger extends Model
{
- /**
- * Checks whether this trigger will match all transactions
- * For example: amount > 0 or description starts with ''
- */
- public function matchesAnything()
- {
- return TriggerFactory::getTrigger($this, new TransactionJournal)->matchesAnything();
- }
-
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
diff --git a/app/Rules/Triggers/AmountExactly.php b/app/Rules/Triggers/AmountExactly.php
index 879d842681..2ea3afdc3a 100644
--- a/app/Rules/Triggers/AmountExactly.php
+++ b/app/Rules/Triggers/AmountExactly.php
@@ -64,18 +64,6 @@ class AmountExactly implements TriggerInterface
return true;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return false;
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/AmountLess.php b/app/Rules/Triggers/AmountLess.php
index d0719ff76d..991d6365a3 100644
--- a/app/Rules/Triggers/AmountLess.php
+++ b/app/Rules/Triggers/AmountLess.php
@@ -64,18 +64,6 @@ class AmountLess implements TriggerInterface
return true;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return false;
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/AmountMore.php b/app/Rules/Triggers/AmountMore.php
index ae5d86dc86..104d0363ef 100644
--- a/app/Rules/Triggers/AmountMore.php
+++ b/app/Rules/Triggers/AmountMore.php
@@ -64,18 +64,6 @@ class AmountMore implements TriggerInterface
return true;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return bccomp('0', $this->trigger->trigger_value) === 0;
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/DescriptionContains.php b/app/Rules/Triggers/DescriptionContains.php
index 9156ea4d74..0d760016c9 100644
--- a/app/Rules/Triggers/DescriptionContains.php
+++ b/app/Rules/Triggers/DescriptionContains.php
@@ -64,18 +64,6 @@ class DescriptionContains implements TriggerInterface
return true;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return $this->trigger->trigger_value === "";
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/DescriptionEnds.php b/app/Rules/Triggers/DescriptionEnds.php
index bd0a8d0ce7..951cf8d7e1 100644
--- a/app/Rules/Triggers/DescriptionEnds.php
+++ b/app/Rules/Triggers/DescriptionEnds.php
@@ -63,18 +63,6 @@ class DescriptionEnds implements TriggerInterface
return true;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return $this->trigger->trigger_value === "";
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/DescriptionIs.php b/app/Rules/Triggers/DescriptionIs.php
index 8f0b556b8d..713aaa8fc8 100644
--- a/app/Rules/Triggers/DescriptionIs.php
+++ b/app/Rules/Triggers/DescriptionIs.php
@@ -38,18 +38,6 @@ class DescriptionIs implements TriggerInterface
$this->journal = $journal;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return false;
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/DescriptionStarts.php b/app/Rules/Triggers/DescriptionStarts.php
index 2d91dc01ad..a9cc27a44a 100644
--- a/app/Rules/Triggers/DescriptionStarts.php
+++ b/app/Rules/Triggers/DescriptionStarts.php
@@ -38,18 +38,6 @@ class DescriptionStarts implements TriggerInterface
$this->journal = $journal;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return $this->trigger->trigger_value === "";
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/FromAccountContains.php b/app/Rules/Triggers/FromAccountContains.php
index d5a2113288..8e600b4d95 100644
--- a/app/Rules/Triggers/FromAccountContains.php
+++ b/app/Rules/Triggers/FromAccountContains.php
@@ -38,18 +38,6 @@ class FromAccountContains implements TriggerInterface
$this->journal = $journal;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return $this->trigger->trigger_value === "";
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/FromAccountEnds.php b/app/Rules/Triggers/FromAccountEnds.php
index 617f7eb037..0c49e371e8 100644
--- a/app/Rules/Triggers/FromAccountEnds.php
+++ b/app/Rules/Triggers/FromAccountEnds.php
@@ -38,18 +38,6 @@ class FromAccountEnds implements TriggerInterface
$this->journal = $journal;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return $this->trigger->trigger_value === "";
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/FromAccountIs.php b/app/Rules/Triggers/FromAccountIs.php
index 7f73fc6e9f..322890b90e 100644
--- a/app/Rules/Triggers/FromAccountIs.php
+++ b/app/Rules/Triggers/FromAccountIs.php
@@ -63,18 +63,6 @@ class FromAccountIs implements TriggerInterface
return true;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return false;
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/FromAccountStarts.php b/app/Rules/Triggers/FromAccountStarts.php
index 954711de95..e4b94aa896 100644
--- a/app/Rules/Triggers/FromAccountStarts.php
+++ b/app/Rules/Triggers/FromAccountStarts.php
@@ -63,18 +63,6 @@ class FromAccountStarts implements TriggerInterface
return true;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return $this->trigger->trigger_value === "";
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/ToAccountContains.php b/app/Rules/Triggers/ToAccountContains.php
index e0f826a6e4..0f823d453f 100644
--- a/app/Rules/Triggers/ToAccountContains.php
+++ b/app/Rules/Triggers/ToAccountContains.php
@@ -38,18 +38,6 @@ class ToAccountContains implements TriggerInterface
$this->journal = $journal;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return $this->trigger->trigger_value === "";
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/ToAccountEnds.php b/app/Rules/Triggers/ToAccountEnds.php
index 1c8bf21eb7..3542b0594c 100644
--- a/app/Rules/Triggers/ToAccountEnds.php
+++ b/app/Rules/Triggers/ToAccountEnds.php
@@ -38,18 +38,6 @@ class ToAccountEnds implements TriggerInterface
$this->journal = $journal;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return $this->trigger->trigger_value === "";
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/ToAccountIs.php b/app/Rules/Triggers/ToAccountIs.php
index b5a39b752c..7034d19072 100644
--- a/app/Rules/Triggers/ToAccountIs.php
+++ b/app/Rules/Triggers/ToAccountIs.php
@@ -38,18 +38,6 @@ class ToAccountIs implements TriggerInterface
$this->journal = $journal;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return false;
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/ToAccountStarts.php b/app/Rules/Triggers/ToAccountStarts.php
index 78fc07c77a..57242382ce 100644
--- a/app/Rules/Triggers/ToAccountStarts.php
+++ b/app/Rules/Triggers/ToAccountStarts.php
@@ -38,18 +38,6 @@ class ToAccountStarts implements TriggerInterface
$this->journal = $journal;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return $this->trigger->trigger_value === "";
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/TransactionType.php b/app/Rules/Triggers/TransactionType.php
index 1beb3478d6..2573a0ef96 100644
--- a/app/Rules/Triggers/TransactionType.php
+++ b/app/Rules/Triggers/TransactionType.php
@@ -38,18 +38,6 @@ class TransactionType implements TriggerInterface
$this->journal = $journal;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return false;
- }
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/TriggerInterface.php b/app/Rules/Triggers/TriggerInterface.php
index 355a03d9e0..1fa4c77ac2 100644
--- a/app/Rules/Triggers/TriggerInterface.php
+++ b/app/Rules/Triggers/TriggerInterface.php
@@ -46,22 +46,6 @@ interface TriggerInterface
*/
public static function willMatchEverything($value = null);
- /**
- * 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.
- *
- * @return bool
- */
- public function matchesAnything();
-
/**
* @return bool
*/
diff --git a/app/Rules/Triggers/UserAction.php b/app/Rules/Triggers/UserAction.php
index a2acb3c1f7..f9e2046dfe 100644
--- a/app/Rules/Triggers/UserAction.php
+++ b/app/Rules/Triggers/UserAction.php
@@ -60,18 +60,6 @@ class UserAction implements TriggerInterface
return true;
}
- /**
- * @{inheritdoc}
- *
- * @see TriggerInterface::matchesAnything
- *
- * @return bool
- */
- public function matchesAnything()
- {
- return true;
- }
-
/**
* This trigger is always triggered, because the rule that it is a part of has been pre-selected on this condition.
*
diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php
index a225b4376f..ed447e81c1 100644
--- a/app/Validation/FireflyValidator.php
+++ b/app/Validation/FireflyValidator.php
@@ -14,6 +14,7 @@ use FireflyIII\Models\Budget;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
+use FireflyIII\Rules\Triggers\TriggerInterface;
use FireflyIII\User;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Validation\Validator;
@@ -151,18 +152,34 @@ class FireflyValidator extends Validator
if (is_array($this->data['rule-trigger'])) {
$name = $this->getRuleTriggerName($index);
$value = $this->getRuleTriggerValue($index);
+
+ // break on some easy checks:
switch ($name) {
- default:
- return true;
case 'amount_less':
- return is_numeric($value);
+ $result = is_numeric($value);
+ if ($result === false) {
+ return false;
+ }
+ break;
case 'transaction_type':
$count = TransactionType::where('type', $value)->count();
-
- return $count === 1;
+ if (!($count === 1)) {
+ return false;
+ }
+ break;
case 'invalid':
return false;
}
+ // still a special case where the trigger is
+ // triggered in such a way that it would trigger ANYTHING. We can check for such things
+ // with function willmatcheverything
+ // we know which class it is so dont bother checking that.
+ $classes = Config::get('firefly.rule-triggers');
+ /** @var TriggerInterface $class */
+ $class = $classes[$name];
+
+ return !($class::willMatchEverything($value));
+
}
return false;