Fix factory and triggers.

This commit is contained in:
James Cole 2016-02-17 20:19:44 +01:00
parent 694447e66c
commit 51acc34a80
18 changed files with 24 additions and 21 deletions

View File

@ -71,7 +71,7 @@ class AbstractTrigger
*/ */
public static function makeFromTriggerValue(string $triggerValue) public static function makeFromTriggerValue(string $triggerValue)
{ {
$self = new self; $self = new static;
$self->triggerValue = $triggerValue; $self->triggerValue = $triggerValue;
return $self; return $self;

View File

@ -55,7 +55,7 @@ class AmountExactly extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$amount = $journal->amount_positive; $amount = $journal->amount_positive;
$compare = $this->trigger->trigger_value; $compare = $this->triggerValue;
$result = bccomp($amount, $compare, 4); $result = bccomp($amount, $compare, 4);
if ($result === 0) { if ($result === 0) {
// found something // found something

View File

@ -55,7 +55,7 @@ class AmountLess extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$amount = $journal->amount_positive; $amount = $journal->amount_positive;
$compare = $this->trigger->trigger_value; $compare = $this->triggerValue;
$result = bccomp($amount, $compare, 4); $result = bccomp($amount, $compare, 4);
if ($result === -1) { if ($result === -1) {
// found something // found something

View File

@ -55,7 +55,7 @@ class AmountMore extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$amount = $journal->amount_positive; $amount = $journal->amount_positive;
$compare = $this->trigger->trigger_value; $compare = $this->triggerValue;
$result = bccomp($amount, $compare, 4); $result = bccomp($amount, $compare, 4);
if ($result === 1) { if ($result === 1) {
// found something // found something

View File

@ -54,7 +54,7 @@ class DescriptionContains extends AbstractTrigger implements TriggerInterface
*/ */
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
$source = strtolower($journal->description); $source = strtolower($journal->description);
$strpos = strpos($source, $search); $strpos = strpos($source, $search);

View File

@ -55,7 +55,7 @@ class DescriptionEnds extends AbstractTrigger implements TriggerInterface
{ {
$description = strtolower($journal->description); $description = strtolower($journal->description);
$descriptionLength = strlen($description); $descriptionLength = strlen($description);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
$searchLength = strlen($search); $searchLength = strlen($search);
// if the string to search for is longer than the description, // if the string to search for is longer than the description,

View File

@ -54,7 +54,7 @@ class DescriptionIs extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$description = strtolower($journal->description); $description = strtolower($journal->description);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
if ($description == $search) { if ($description == $search) {
Log::debug('"' . $description . '" equals "' . $search . '" exactly. Return true.'); Log::debug('"' . $description . '" equals "' . $search . '" exactly. Return true.');

View File

@ -54,7 +54,7 @@ class DescriptionStarts extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$description = strtolower($journal->description); $description = strtolower($journal->description);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
$part = substr($description, 0, strlen($search)); $part = substr($description, 0, strlen($search));

View File

@ -54,7 +54,7 @@ class FromAccountContains extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$fromAccountName = strtolower($journal->source_account->name); $fromAccountName = strtolower($journal->source_account->name);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
$strpos = strpos($fromAccountName, $search); $strpos = strpos($fromAccountName, $search);
if (!($strpos === false)) { if (!($strpos === false)) {

View File

@ -55,7 +55,7 @@ class FromAccountEnds extends AbstractTrigger implements TriggerInterface
{ {
$name = strtolower($journal->source_account->name); $name = strtolower($journal->source_account->name);
$nameLength = strlen($name); $nameLength = strlen($name);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
$searchLength = strlen($search); $searchLength = strlen($search);
// if the string to search for is longer than the account name, // if the string to search for is longer than the account name,

View File

@ -54,7 +54,7 @@ class FromAccountIs extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$fromAccountName = strtolower($journal->source_account->name); $fromAccountName = strtolower($journal->source_account->name);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
if ($fromAccountName == $search) { if ($fromAccountName == $search) {
Log::debug('"' . $fromAccountName . '" equals "' . $search . '" exactly. Return true.'); Log::debug('"' . $fromAccountName . '" equals "' . $search . '" exactly. Return true.');

View File

@ -54,7 +54,7 @@ class FromAccountStarts extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$fromAccountName = strtolower($journal->source_account->name); $fromAccountName = strtolower($journal->source_account->name);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
$part = substr($fromAccountName, 0, strlen($search)); $part = substr($fromAccountName, 0, strlen($search));

View File

@ -54,7 +54,7 @@ class ToAccountContains extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$toAccountName = strtolower($journal->destination_account->name); $toAccountName = strtolower($journal->destination_account->name);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
$strpos = strpos($toAccountName, $search); $strpos = strpos($toAccountName, $search);
if (!($strpos === false)) { if (!($strpos === false)) {

View File

@ -55,7 +55,7 @@ class ToAccountEnds extends AbstractTrigger implements TriggerInterface
{ {
$toAccountName = strtolower($journal->destination_account->name); $toAccountName = strtolower($journal->destination_account->name);
$toAccountNameLength = strlen($toAccountName); $toAccountNameLength = strlen($toAccountName);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
$searchLength = strlen($search); $searchLength = strlen($search);
// if the string to search for is longer than the account name, // if the string to search for is longer than the account name,

View File

@ -54,7 +54,7 @@ class ToAccountIs extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$toAccountName = strtolower($journal->destination_account->name); $toAccountName = strtolower($journal->destination_account->name);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
if ($toAccountName == $search) { if ($toAccountName == $search) {
Log::debug('"' . $toAccountName . '" equals "' . $search . '" exactly. Return true.'); Log::debug('"' . $toAccountName . '" equals "' . $search . '" exactly. Return true.');

View File

@ -54,7 +54,7 @@ class ToAccountStarts extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$toAccountName = strtolower($journal->destination_account->name); $toAccountName = strtolower($journal->destination_account->name);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
$part = substr($toAccountName, 0, strlen($search)); $part = substr($toAccountName, 0, strlen($search));

View File

@ -54,7 +54,7 @@ class TransactionType extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal) public function triggered(TransactionJournal $journal)
{ {
$type = strtolower($journal->transactionType->type); $type = strtolower($journal->transactionType->type);
$search = strtolower($this->trigger->trigger_value); $search = strtolower($this->triggerValue);
if ($type == $search) { if ($type == $search) {
Log::debug('Journal is of type "' . $type . '" which matches with "' . $search . '". Return true'); Log::debug('Journal is of type "' . $type . '" which matches with "' . $search . '". Return true');

View File

@ -28,14 +28,17 @@ class TriggerFactory
* *
* @param RuleTrigger $trigger * @param RuleTrigger $trigger
* *
* @return TriggerInterface * @return AbstractTrigger
*/ */
public static function getTrigger(RuleTrigger $trigger): TriggerInterface public static function getTrigger(RuleTrigger $trigger)
{ {
$triggerType = $trigger->trigger_type; $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;
} }
/** /**