From a6c318983350ebcb101cdf04919153c5bc9c2b54 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 17 Feb 2016 18:00:13 +0100 Subject: [PATCH] Add willMatchEveryThing as a static replacement for matchesAnything --- app/Rules/Triggers/AmountExactly.php | 25 +++++++++++++++++++++ app/Rules/Triggers/AmountLess.php | 25 +++++++++++++++++++++ app/Rules/Triggers/AmountMore.php | 25 +++++++++++++++++++++ app/Rules/Triggers/DescriptionContains.php | 25 +++++++++++++++++++++ app/Rules/Triggers/DescriptionEnds.php | 26 +++++++++++++++++++++- app/Rules/Triggers/DescriptionIs.php | 24 ++++++++++++++++++++ app/Rules/Triggers/DescriptionStarts.php | 24 ++++++++++++++++++++ app/Rules/Triggers/FromAccountContains.php | 24 ++++++++++++++++++++ app/Rules/Triggers/FromAccountEnds.php | 24 ++++++++++++++++++++ app/Rules/Triggers/FromAccountIs.php | 26 +++++++++++++++++++++- app/Rules/Triggers/FromAccountStarts.php | 26 +++++++++++++++++++++- app/Rules/Triggers/ToAccountContains.php | 25 +++++++++++++++++++++ app/Rules/Triggers/ToAccountEnds.php | 25 +++++++++++++++++++++ app/Rules/Triggers/ToAccountIs.php | 24 ++++++++++++++++++++ app/Rules/Triggers/ToAccountStarts.php | 24 ++++++++++++++++++++ app/Rules/Triggers/TransactionType.php | 24 ++++++++++++++++++++ app/Rules/Triggers/TriggerInterface.php | 18 +++++++++++++++ app/Rules/Triggers/UserAction.php | 22 +++++++++++++++++- 18 files changed, 432 insertions(+), 4 deletions(-) diff --git a/app/Rules/Triggers/AmountExactly.php b/app/Rules/Triggers/AmountExactly.php index 03af0bec25..879d842681 100644 --- a/app/Rules/Triggers/AmountExactly.php +++ b/app/Rules/Triggers/AmountExactly.php @@ -39,6 +39,31 @@ class AmountExactly implements TriggerInterface $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 false; + } + + return true; + } + /** * @{inheritdoc} * diff --git a/app/Rules/Triggers/AmountLess.php b/app/Rules/Triggers/AmountLess.php index 5a9c72976b..d0719ff76d 100644 --- a/app/Rules/Triggers/AmountLess.php +++ b/app/Rules/Triggers/AmountLess.php @@ -39,6 +39,31 @@ class AmountLess implements TriggerInterface $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 false; + } + + return true; + } + /** * @{inheritdoc} * diff --git a/app/Rules/Triggers/AmountMore.php b/app/Rules/Triggers/AmountMore.php index 27ea6e02c3..ae5d86dc86 100644 --- a/app/Rules/Triggers/AmountMore.php +++ b/app/Rules/Triggers/AmountMore.php @@ -39,6 +39,31 @@ class AmountMore implements TriggerInterface $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 bccomp('0', strval($value)) === 0; + } + + return true; + } + /** * @{inheritdoc} * diff --git a/app/Rules/Triggers/DescriptionContains.php b/app/Rules/Triggers/DescriptionContains.php index e0949a60ee..9156ea4d74 100644 --- a/app/Rules/Triggers/DescriptionContains.php +++ b/app/Rules/Triggers/DescriptionContains.php @@ -39,6 +39,31 @@ class DescriptionContains implements TriggerInterface $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; + } + /** * @{inheritdoc} * diff --git a/app/Rules/Triggers/DescriptionEnds.php b/app/Rules/Triggers/DescriptionEnds.php index 406fb385b9..bd0a8d0ce7 100644 --- a/app/Rules/Triggers/DescriptionEnds.php +++ b/app/Rules/Triggers/DescriptionEnds.php @@ -38,6 +38,31 @@ class DescriptionEnds implements TriggerInterface $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; + } + /** * @{inheritdoc} * @@ -82,5 +107,4 @@ class DescriptionEnds implements TriggerInterface return false; } - } diff --git a/app/Rules/Triggers/DescriptionIs.php b/app/Rules/Triggers/DescriptionIs.php index f6cedfd335..8f0b556b8d 100644 --- a/app/Rules/Triggers/DescriptionIs.php +++ b/app/Rules/Triggers/DescriptionIs.php @@ -69,4 +69,28 @@ class DescriptionIs implements TriggerInterface } + /** + * 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 false; + } + + return true; + } } diff --git a/app/Rules/Triggers/DescriptionStarts.php b/app/Rules/Triggers/DescriptionStarts.php index f5ad96953d..2d91dc01ad 100644 --- a/app/Rules/Triggers/DescriptionStarts.php +++ b/app/Rules/Triggers/DescriptionStarts.php @@ -71,4 +71,28 @@ class DescriptionStarts implements TriggerInterface } + /** + * 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/FromAccountContains.php b/app/Rules/Triggers/FromAccountContains.php index c7e28041ba..d5a2113288 100644 --- a/app/Rules/Triggers/FromAccountContains.php +++ b/app/Rules/Triggers/FromAccountContains.php @@ -73,4 +73,28 @@ class FromAccountContains implements TriggerInterface } + /** + * 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/FromAccountEnds.php b/app/Rules/Triggers/FromAccountEnds.php index 79659fad98..617f7eb037 100644 --- a/app/Rules/Triggers/FromAccountEnds.php +++ b/app/Rules/Triggers/FromAccountEnds.php @@ -83,4 +83,28 @@ class FromAccountEnds implements TriggerInterface } + /** + * 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 07265484f8..7f73fc6e9f 100644 --- a/app/Rules/Triggers/FromAccountIs.php +++ b/app/Rules/Triggers/FromAccountIs.php @@ -38,6 +38,31 @@ class FromAccountIs implements TriggerInterface $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 false; + } + + return true; + } + /** * @{inheritdoc} * @@ -68,5 +93,4 @@ class FromAccountIs implements TriggerInterface return false; } - } diff --git a/app/Rules/Triggers/FromAccountStarts.php b/app/Rules/Triggers/FromAccountStarts.php index 7588769ed4..954711de95 100644 --- a/app/Rules/Triggers/FromAccountStarts.php +++ b/app/Rules/Triggers/FromAccountStarts.php @@ -38,6 +38,31 @@ class FromAccountStarts implements TriggerInterface $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; + } + /** * @{inheritdoc} * @@ -70,5 +95,4 @@ class FromAccountStarts implements TriggerInterface return false; } - } diff --git a/app/Rules/Triggers/ToAccountContains.php b/app/Rules/Triggers/ToAccountContains.php index b55d592bec..e0f826a6e4 100644 --- a/app/Rules/Triggers/ToAccountContains.php +++ b/app/Rules/Triggers/ToAccountContains.php @@ -73,4 +73,29 @@ class ToAccountContains implements TriggerInterface } + + /** + * 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/ToAccountEnds.php b/app/Rules/Triggers/ToAccountEnds.php index 0dc9d757c8..1c8bf21eb7 100644 --- a/app/Rules/Triggers/ToAccountEnds.php +++ b/app/Rules/Triggers/ToAccountEnds.php @@ -82,4 +82,29 @@ 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 1d389ca5dd..b5a39b752c 100644 --- a/app/Rules/Triggers/ToAccountIs.php +++ b/app/Rules/Triggers/ToAccountIs.php @@ -69,4 +69,28 @@ class ToAccountIs implements TriggerInterface } + /** + * 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 false; + } + + return true; + } } diff --git a/app/Rules/Triggers/ToAccountStarts.php b/app/Rules/Triggers/ToAccountStarts.php index e9d5b8caa7..78fc07c77a 100644 --- a/app/Rules/Triggers/ToAccountStarts.php +++ b/app/Rules/Triggers/ToAccountStarts.php @@ -71,4 +71,28 @@ class ToAccountStarts implements TriggerInterface } + /** + * 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/TransactionType.php b/app/Rules/Triggers/TransactionType.php index 4a47604a66..1beb3478d6 100644 --- a/app/Rules/Triggers/TransactionType.php +++ b/app/Rules/Triggers/TransactionType.php @@ -68,4 +68,28 @@ class TransactionType 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 false; + } + + return true; + } } diff --git a/app/Rules/Triggers/TriggerInterface.php b/app/Rules/Triggers/TriggerInterface.php index 2c8f61f4f8..355a03d9e0 100644 --- a/app/Rules/Triggers/TriggerInterface.php +++ b/app/Rules/Triggers/TriggerInterface.php @@ -28,6 +28,24 @@ interface TriggerInterface */ public function __construct(RuleTrigger $trigger, TransactionJournal $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); + /** * 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 diff --git a/app/Rules/Triggers/UserAction.php b/app/Rules/Triggers/UserAction.php index c9fdcc78a2..a2acb3c1f7 100644 --- a/app/Rules/Triggers/UserAction.php +++ b/app/Rules/Triggers/UserAction.php @@ -39,6 +39,27 @@ class UserAction implements TriggerInterface } + /** + * 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) + { + return true; + } + /** * @{inheritdoc} * @@ -62,5 +83,4 @@ class UserAction implements TriggerInterface return true; } - }