mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-04 04:30:39 -06:00
Remove matchesAnything
This commit is contained in:
parent
a6c3189833
commit
28fa1264b7
@ -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
|
||||
*/
|
||||
|
@ -64,18 +64,6 @@ class AmountExactly implements TriggerInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @{inheritdoc}
|
||||
*
|
||||
* @see TriggerInterface::matchesAnything
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function matchesAnything()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -64,18 +64,6 @@ class AmountLess implements TriggerInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @{inheritdoc}
|
||||
*
|
||||
* @see TriggerInterface::matchesAnything
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function matchesAnything()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -38,18 +38,6 @@ class DescriptionIs implements TriggerInterface
|
||||
$this->journal = $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @{inheritdoc}
|
||||
*
|
||||
* @see TriggerInterface::matchesAnything
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function matchesAnything()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -63,18 +63,6 @@ class FromAccountIs implements TriggerInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @{inheritdoc}
|
||||
*
|
||||
* @see TriggerInterface::matchesAnything
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function matchesAnything()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -38,18 +38,6 @@ class ToAccountIs implements TriggerInterface
|
||||
$this->journal = $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @{inheritdoc}
|
||||
*
|
||||
* @see TriggerInterface::matchesAnything
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function matchesAnything()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -38,18 +38,6 @@ class TransactionType implements TriggerInterface
|
||||
$this->journal = $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @{inheritdoc}
|
||||
*
|
||||
* @see TriggerInterface::matchesAnything
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function matchesAnything()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user