Code formatting.

This commit is contained in:
James Cole 2016-02-17 15:29:26 +01:00
parent b3e18f4e56
commit 52481a6e8b
19 changed files with 121 additions and 65 deletions

View File

@ -62,11 +62,15 @@ class AmountExactly implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* For example: amount > 0 or description starts with '' * For example: amount > 0 or description starts with ''
*
* @return bool * @return bool
*/ */
public function matchesAnything() { return false; } public function matchesAnything()
{
return false;
}
} }

View File

@ -62,11 +62,15 @@ class AmountLess implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* For example: amount > 0 or description starts with '' * For example: amount > 0 or description starts with ''
*
* @return bool * @return bool
*/ */
public function matchesAnything() { return false; } public function matchesAnything()
{
return false;
}
} }

View File

@ -62,13 +62,15 @@ class AmountMore implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* This happens when the trigger_value is zero * This happens when the trigger_value is zero
*
* @return bool * @return bool
*/ */
public function matchesAnything() { public function matchesAnything()
return bccomp('0', $this->trigger->trigger_value) === 0; {
return bccomp('0', $this->trigger->trigger_value) === 0;
} }
} }

View File

@ -63,13 +63,15 @@ class DescriptionContains implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* This happens when the trigger_value is empty * This happens when the trigger_value is empty
*
* @return bool * @return bool
*/ */
public function matchesAnything() { public function matchesAnything()
{
return $this->trigger->trigger_value === ""; return $this->trigger->trigger_value === "";
} }
} }

View File

@ -72,14 +72,16 @@ class DescriptionEnds implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* This happens when the trigger_value is empty * This happens when the trigger_value is empty
*
* @return bool * @return bool
*/ */
public function matchesAnything() { public function matchesAnything()
{
return $this->trigger->trigger_value === ""; return $this->trigger->trigger_value === "";
} }
} }

View File

@ -58,11 +58,15 @@ class DescriptionIs implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
*
* @return bool * @return bool
*/ */
public function matchesAnything() { return false; } public function matchesAnything()
{
return false;
}
} }

View File

@ -60,14 +60,16 @@ class DescriptionStarts implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* This happens when the trigger_value is empty * This happens when the trigger_value is empty
*
* @return bool * @return bool
*/ */
public function matchesAnything() { public function matchesAnything()
{
return $this->trigger->trigger_value === ""; return $this->trigger->trigger_value === "";
} }
} }

View File

@ -62,14 +62,16 @@ class FromAccountContains implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* This happens when the trigger_value is empty * This happens when the trigger_value is empty
*
* @return bool * @return bool
*/ */
public function matchesAnything() { public function matchesAnything()
{
return $this->trigger->trigger_value === ""; return $this->trigger->trigger_value === "";
} }
} }

View File

@ -72,15 +72,17 @@ class FromAccountEnds implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* This happens when the trigger_value is empty * This happens when the trigger_value is empty
*
* @return bool * @return bool
*/ */
public function matchesAnything() { public function matchesAnything()
{
return $this->trigger->trigger_value === ""; return $this->trigger->trigger_value === "";
} }
} }

View File

@ -61,8 +61,12 @@ class FromAccountIs implements TriggerInterface
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
*
* @return bool * @return bool
*/ */
public function matchesAnything() { return false; } public function matchesAnything()
{
return false;
}
} }

View File

@ -60,15 +60,17 @@ class FromAccountStarts implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* This happens when the trigger_value is empty * This happens when the trigger_value is empty
*
* @return bool * @return bool
*/ */
public function matchesAnything() { public function matchesAnything()
{
return $this->trigger->trigger_value === ""; return $this->trigger->trigger_value === "";
} }
} }

View File

@ -62,15 +62,17 @@ class ToAccountContains implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* This happens when the trigger_value is empty * This happens when the trigger_value is empty
*
* @return bool * @return bool
*/ */
public function matchesAnything() { public function matchesAnything()
{
return $this->trigger->trigger_value === ""; return $this->trigger->trigger_value === "";
} }
} }

View File

@ -72,14 +72,16 @@ class ToAccountEnds implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* This happens when the trigger_value is empty * This happens when the trigger_value is empty
*
* @return bool * @return bool
*/ */
public function matchesAnything() { public function matchesAnything()
{
return $this->trigger->trigger_value === ""; return $this->trigger->trigger_value === "";
} }
} }

View File

@ -58,11 +58,15 @@ class ToAccountIs implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
*
* @return bool * @return bool
*/ */
public function matchesAnything() { return false; } public function matchesAnything()
{
return false;
}
} }

View File

@ -60,15 +60,17 @@ class ToAccountStarts implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* This happens when the trigger_value is empty * This happens when the trigger_value is empty
*
* @return bool * @return bool
*/ */
public function matchesAnything() { public function matchesAnything()
{
return $this->trigger->trigger_value === ""; return $this->trigger->trigger_value === "";
} }
} }

View File

@ -57,11 +57,15 @@ class TransactionType implements TriggerInterface
return false; return false;
} }
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
*
* @return bool * @return bool
*/ */
public function matchesAnything() { return false; } public function matchesAnything()
{
return false;
}
} }

View File

@ -22,48 +22,55 @@ use FireflyIII\Support\Domain;
class TriggerFactory class TriggerFactory
{ {
protected static $triggerTypes = null; protected static $triggerTypes = null;
/** /**
* Returns the class name to be used for triggers with the given name * Returns the class name to be used for triggers with the given name
*
* @param string $triggerType * @param string $triggerType
*
* @return TriggerInterface * @return TriggerInterface
*/ */
public static function getTriggerClass(string $triggerType): string { public static function getTriggerClass(string $triggerType): string
{
$triggerTypes = self::getTriggerTypes(); $triggerTypes = self::getTriggerTypes();
if (!array_key_exists($triggerType, $triggerTypes)) { if (!array_key_exists($triggerType, $triggerTypes)) {
abort(500, 'No such trigger exists ("' . $triggerType . '").'); abort(500, 'No such trigger exists ("' . $triggerType . '").');
} }
$class = $triggerTypes[$triggerType]; $class = $triggerTypes[$triggerType];
if (!class_exists($class)) { if (!class_exists($class)) {
abort(500, 'Could not instantiate class for rule trigger type "' . $triggerType . '" (' . $class . ').'); abort(500, 'Could not instantiate class for rule trigger type "' . $triggerType . '" (' . $class . ').');
} }
return $class; return $class;
} }
/** /**
* Returns the trigger for the given type and journal * Returns the trigger for the given type and journal
* @param RuleTrigger $trigger *
* @param RuleTrigger $trigger
* @param TransactionJournal $journal * @param TransactionJournal $journal
*
* @return TriggerInterface * @return TriggerInterface
*/ */
public static function getTrigger(RuleTrigger $trigger, TransactionJournal $journal): TriggerInterface { public static function getTrigger(RuleTrigger $trigger, TransactionJournal $journal): TriggerInterface
{
$triggerType = $trigger->trigger_type; $triggerType = $trigger->trigger_type;
$class = self::getTriggerClass($triggerType); $class = self::getTriggerClass($triggerType);
return new $class($trigger, $journal); return new $class($trigger, $journal);
} }
/** /**
* Returns a map with triggertypes, mapped to the class representing that type * Returns a map with triggertypes, mapped to the class representing that type
*/ */
protected static function getTriggerTypes() { protected static function getTriggerTypes()
if( !self::$triggerTypes ) { {
if (!self::$triggerTypes) {
self::$triggerTypes = Domain::getRuleTriggers(); self::$triggerTypes = Domain::getRuleTriggers();
} }
return self::$triggerTypes; return self::$triggerTypes;
} }
} }

View File

@ -28,15 +28,16 @@ interface TriggerInterface
*/ */
public function __construct(RuleTrigger $trigger, TransactionJournal $journal); public function __construct(RuleTrigger $trigger, TransactionJournal $journal);
/**
* @return bool
*/
public function triggered();
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
* For example: amount > 0 or description starts with '' * For example: amount > 0 or description starts with ''
*
* @return bool * @return bool
*/ */
public function matchesAnything(); public function matchesAnything();
/**
* @return bool
*/
public function triggered();
} }

View File

@ -55,8 +55,12 @@ class UserAction implements TriggerInterface
/** /**
* Checks whether this trigger will match all transactions * Checks whether this trigger will match all transactions
*
* @return bool * @return bool
*/ */
public function matchesAnything() { return true; } public function matchesAnything()
{
return true;
}
} }