From a31b4ccf01c4bef28b210502d7a3ad1a53ae9af7 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 21 Sep 2016 20:30:09 +0200 Subject: [PATCH] Basic logging for willMatchEverything #322 --- app/Rules/Factory/ActionFactory.php | 4 ++-- app/Rules/Factory/TriggerFactory.php | 3 +++ app/Rules/Triggers/AmountExactly.php | 2 ++ app/Rules/Triggers/AmountLess.php | 2 ++ app/Rules/Triggers/AmountMore.php | 10 +++++++++- app/Rules/Triggers/DescriptionContains.php | 10 +++++++++- app/Rules/Triggers/DescriptionEnds.php | 10 +++++++++- app/Rules/Triggers/DescriptionIs.php | 3 +++ app/Rules/Triggers/DescriptionStarts.php | 10 +++++++++- app/Rules/Triggers/FromAccountContains.php | 9 ++++++++- app/Rules/Triggers/FromAccountEnds.php | 9 ++++++++- app/Rules/Triggers/FromAccountIs.php | 3 ++- app/Rules/Triggers/FromAccountStarts.php | 9 ++++++++- app/Rules/Triggers/ToAccountContains.php | 9 ++++++++- app/Rules/Triggers/ToAccountEnds.php | 9 ++++++++- app/Rules/Triggers/ToAccountIs.php | 9 ++++++++- app/Rules/Triggers/ToAccountStarts.php | 9 ++++++++- app/Rules/Triggers/TransactionType.php | 2 ++ 18 files changed, 108 insertions(+), 14 deletions(-) diff --git a/app/Rules/Factory/ActionFactory.php b/app/Rules/Factory/ActionFactory.php index e16a4c89e9..34ed948c19 100644 --- a/app/Rules/Factory/ActionFactory.php +++ b/app/Rules/Factory/ActionFactory.php @@ -8,14 +8,13 @@ declare(strict_types = 1); * of the MIT license. See the LICENSE file for details. */ -declare(strict_types = 1); - namespace FireflyIII\Rules\Factory; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\RuleAction; use FireflyIII\Rules\Actions\ActionInterface; use FireflyIII\Support\Domain; +use Log; /** * Interface ActionInterface @@ -39,6 +38,7 @@ class ActionFactory public static function getAction(RuleAction $action): ActionInterface { $class = self::getActionClass($action->action_type); + Log::debug(sprintf('self::getActionClass("%s") = "%s"', $action->action_type, $class)); return new $class($action); } diff --git a/app/Rules/Factory/TriggerFactory.php b/app/Rules/Factory/TriggerFactory.php index 65cbf1bcde..f8d94fe3b7 100644 --- a/app/Rules/Factory/TriggerFactory.php +++ b/app/Rules/Factory/TriggerFactory.php @@ -46,6 +46,9 @@ class TriggerFactory $class = self::getTriggerClass($triggerType); $obj = $class::makeFromTriggerValue($trigger->trigger_value); + Log::debug(sprintf('self::getTriggerClass("%s") = "%s"', $triggerType, $class)); + Log::debug(sprintf('%s::makeFromTriggerValue(%s) = object of class "%s"', $class, $trigger->trigger_value, get_class($obj))); + return $obj; } diff --git a/app/Rules/Triggers/AmountExactly.php b/app/Rules/Triggers/AmountExactly.php index 4adfc63604..ba628bc0e4 100644 --- a/app/Rules/Triggers/AmountExactly.php +++ b/app/Rules/Triggers/AmountExactly.php @@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class AmountExactly @@ -43,6 +44,7 @@ final class AmountExactly extends AbstractTrigger implements TriggerInterface if (!is_null($value)) { return false; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); return true; } diff --git a/app/Rules/Triggers/AmountLess.php b/app/Rules/Triggers/AmountLess.php index d90711c7b6..051217315f 100644 --- a/app/Rules/Triggers/AmountLess.php +++ b/app/Rules/Triggers/AmountLess.php @@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class AmountLess @@ -43,6 +44,7 @@ final class AmountLess extends AbstractTrigger implements TriggerInterface if (!is_null($value)) { return false; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); return true; } diff --git a/app/Rules/Triggers/AmountMore.php b/app/Rules/Triggers/AmountMore.php index 66181e8a98..976f2ba487 100644 --- a/app/Rules/Triggers/AmountMore.php +++ b/app/Rules/Triggers/AmountMore.php @@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class AmountMore @@ -41,9 +42,16 @@ final class AmountMore extends AbstractTrigger implements TriggerInterface public static function willMatchEverything($value = null) { if (!is_null($value)) { - return bccomp('0', strval($value)) === 0; + $res = bccomp('0', strval($value)) === 0; + if ($res === true) { + Log::error(sprintf('Cannot use %s with a value equal to 0.', self::class)); + } + + return $res; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); + return true; } diff --git a/app/Rules/Triggers/DescriptionContains.php b/app/Rules/Triggers/DescriptionContains.php index 9cec4a14c4..6b52a2b283 100644 --- a/app/Rules/Triggers/DescriptionContains.php +++ b/app/Rules/Triggers/DescriptionContains.php @@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class DescriptionContains @@ -41,9 +42,16 @@ final class DescriptionContains extends AbstractTrigger implements TriggerInterf public static function willMatchEverything($value = null) { if (!is_null($value)) { - return strval($value) === ''; + $res = strval($value) === ''; + if ($res === true) { + Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); + } + + return $res; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); + return true; } diff --git a/app/Rules/Triggers/DescriptionEnds.php b/app/Rules/Triggers/DescriptionEnds.php index e05227e410..34a2470df4 100644 --- a/app/Rules/Triggers/DescriptionEnds.php +++ b/app/Rules/Triggers/DescriptionEnds.php @@ -12,6 +12,7 @@ declare(strict_types = 1); namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class DescriptionEnds @@ -40,9 +41,16 @@ final class DescriptionEnds extends AbstractTrigger implements TriggerInterface public static function willMatchEverything($value = null) { if (!is_null($value)) { - return strval($value) === ''; + $res = strval($value) === ''; + if ($res === true) { + Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); + } + + return $res; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); + return true; } diff --git a/app/Rules/Triggers/DescriptionIs.php b/app/Rules/Triggers/DescriptionIs.php index 71e6e5c1ad..da1fb965f7 100644 --- a/app/Rules/Triggers/DescriptionIs.php +++ b/app/Rules/Triggers/DescriptionIs.php @@ -12,6 +12,7 @@ declare(strict_types = 1); namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class DescriptionIs @@ -43,6 +44,8 @@ final class DescriptionIs extends AbstractTrigger implements TriggerInterface return false; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); + return true; } diff --git a/app/Rules/Triggers/DescriptionStarts.php b/app/Rules/Triggers/DescriptionStarts.php index e856522a4a..e4c1bf07e6 100644 --- a/app/Rules/Triggers/DescriptionStarts.php +++ b/app/Rules/Triggers/DescriptionStarts.php @@ -12,6 +12,7 @@ declare(strict_types = 1); namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class DescriptionStarts @@ -40,9 +41,16 @@ final class DescriptionStarts extends AbstractTrigger implements TriggerInterfac public static function willMatchEverything($value = null) { if (!is_null($value)) { - return strval($value) === ''; + $res = strval($value) === ''; + if ($res === true) { + Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); + } + + return $res; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); + return true; } diff --git a/app/Rules/Triggers/FromAccountContains.php b/app/Rules/Triggers/FromAccountContains.php index 70f2045277..6d02425d22 100644 --- a/app/Rules/Triggers/FromAccountContains.php +++ b/app/Rules/Triggers/FromAccountContains.php @@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\Account; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class FromAccountContains @@ -41,8 +42,14 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf public static function willMatchEverything($value = null) { if (!is_null($value)) { - return strval($value) === ''; + $res = strval($value) === ''; + if ($res === true) { + Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); + } + + return $res; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); return true; } diff --git a/app/Rules/Triggers/FromAccountEnds.php b/app/Rules/Triggers/FromAccountEnds.php index 319683e87f..921f2267a0 100644 --- a/app/Rules/Triggers/FromAccountEnds.php +++ b/app/Rules/Triggers/FromAccountEnds.php @@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\Account; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class FromAccountEnds @@ -41,8 +42,14 @@ final class FromAccountEnds extends AbstractTrigger implements TriggerInterface public static function willMatchEverything($value = null) { if (!is_null($value)) { - return strval($value) === ''; + $res = strval($value) === ''; + if ($res === true) { + Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); + } + + return $res; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); return true; } diff --git a/app/Rules/Triggers/FromAccountIs.php b/app/Rules/Triggers/FromAccountIs.php index dcd9587556..4855593399 100644 --- a/app/Rules/Triggers/FromAccountIs.php +++ b/app/Rules/Triggers/FromAccountIs.php @@ -13,7 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\Account; use FireflyIII\Models\TransactionJournal; - +use Log; /** * Class FromAccountIs * @@ -43,6 +43,7 @@ final class FromAccountIs extends AbstractTrigger implements TriggerInterface if (!is_null($value)) { return false; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); return true; } diff --git a/app/Rules/Triggers/FromAccountStarts.php b/app/Rules/Triggers/FromAccountStarts.php index 71a84e253d..5b9534c265 100644 --- a/app/Rules/Triggers/FromAccountStarts.php +++ b/app/Rules/Triggers/FromAccountStarts.php @@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\Account; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class FromAccountStarts @@ -41,8 +42,14 @@ final class FromAccountStarts extends AbstractTrigger implements TriggerInterfac public static function willMatchEverything($value = null) { if (!is_null($value)) { - return strval($value) === ''; + $res = strval($value) === ''; + if ($res === true) { + Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); + } + + return $res; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); return true; } diff --git a/app/Rules/Triggers/ToAccountContains.php b/app/Rules/Triggers/ToAccountContains.php index 150f149b14..45b22eaa87 100644 --- a/app/Rules/Triggers/ToAccountContains.php +++ b/app/Rules/Triggers/ToAccountContains.php @@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\Account; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class ToAccountContains @@ -41,8 +42,14 @@ final class ToAccountContains extends AbstractTrigger implements TriggerInterfac public static function willMatchEverything($value = null) { if (!is_null($value)) { - return strval($value) === ''; + $res = strval($value) === ''; + if ($res === true) { + Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); + } + + return $res; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); return true; } diff --git a/app/Rules/Triggers/ToAccountEnds.php b/app/Rules/Triggers/ToAccountEnds.php index 9f4d6e0da7..6e15f04464 100644 --- a/app/Rules/Triggers/ToAccountEnds.php +++ b/app/Rules/Triggers/ToAccountEnds.php @@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\Account; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class ToAccountEnds @@ -41,8 +42,14 @@ final class ToAccountEnds extends AbstractTrigger implements TriggerInterface public static function willMatchEverything($value = null) { if (!is_null($value)) { - return strval($value) === ''; + $res = strval($value) === ''; + if ($res === true) { + Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); + } + + return $res; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); return true; } diff --git a/app/Rules/Triggers/ToAccountIs.php b/app/Rules/Triggers/ToAccountIs.php index 613770b97f..8e4d9fc2ee 100644 --- a/app/Rules/Triggers/ToAccountIs.php +++ b/app/Rules/Triggers/ToAccountIs.php @@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\Account; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class ToAccountIs @@ -41,8 +42,14 @@ final class ToAccountIs extends AbstractTrigger implements TriggerInterface public static function willMatchEverything($value = null) { if (!is_null($value)) { - return false; + $res = strval($value) === ''; + if ($res === true) { + Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); + } + + return $res; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); return true; } diff --git a/app/Rules/Triggers/ToAccountStarts.php b/app/Rules/Triggers/ToAccountStarts.php index 3dab74bd09..27ef226955 100644 --- a/app/Rules/Triggers/ToAccountStarts.php +++ b/app/Rules/Triggers/ToAccountStarts.php @@ -13,6 +13,7 @@ namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\Account; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class ToAccountStarts @@ -41,8 +42,14 @@ final class ToAccountStarts extends AbstractTrigger implements TriggerInterface public static function willMatchEverything($value = null) { if (!is_null($value)) { - return strval($value) === ''; + $res = strval($value) === ''; + if ($res === true) { + Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); + } + + return $res; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); return true; } diff --git a/app/Rules/Triggers/TransactionType.php b/app/Rules/Triggers/TransactionType.php index 0abff3d7d5..629e43bd3c 100644 --- a/app/Rules/Triggers/TransactionType.php +++ b/app/Rules/Triggers/TransactionType.php @@ -12,6 +12,7 @@ declare(strict_types = 1); namespace FireflyIII\Rules\Triggers; use FireflyIII\Models\TransactionJournal; +use Log; /** * Class TransactionType @@ -42,6 +43,7 @@ final class TransactionType extends AbstractTrigger implements TriggerInterface if (!is_null($value)) { return false; } + Log::error(sprintf('Cannot use %s with a null value.', self::class)); return true; }