Last code optimization before release.

This commit is contained in:
James Cole
2018-07-28 10:45:16 +02:00
parent d35470a79e
commit 0c7b652a70
42 changed files with 217 additions and 301 deletions

View File

@@ -32,9 +32,6 @@ use Log;
*/
class ClearBudget implements ActionInterface
{
/** @var RuleAction The rule action */
private $action;
/**
* TriggerInterface constructor.
*
@@ -42,7 +39,6 @@ class ClearBudget implements ActionInterface
*/
public function __construct(RuleAction $action)
{
$this->action = $action;
}
/**

View File

@@ -32,9 +32,6 @@ use Log;
*/
class ClearCategory implements ActionInterface
{
/** @var RuleAction The rule action */
private $action;
/**
* TriggerInterface constructor.
*
@@ -42,7 +39,6 @@ class ClearCategory implements ActionInterface
*/
public function __construct(RuleAction $action)
{
$this->action = $action;
}
/**

View File

@@ -32,9 +32,6 @@ use Log;
*/
class ClearNotes implements ActionInterface
{
/** @var RuleAction The rule action */
private $action;
/**
* TriggerInterface constructor.
*
@@ -42,7 +39,6 @@ class ClearNotes implements ActionInterface
*/
public function __construct(RuleAction $action)
{
$this->action = $action;
}
/**

View File

@@ -31,9 +31,6 @@ use Log;
*/
class RemoveAllTags implements ActionInterface
{
/** @var RuleAction The rule action */
private $action;
/**
* TriggerInterface constructor.
*
@@ -41,7 +38,6 @@ class RemoveAllTags implements ActionInterface
*/
public function __construct(RuleAction $action)
{
$this->action = $action;
}
/**

View File

@@ -61,7 +61,11 @@ class SetCategory implements ActionInterface
$factory = app(CategoryFactory::class);
$factory->setUser($journal->user);
$category = $factory->findOrCreate(null, $name);
if (null === $category) {
Log::error(sprintf('Action SetCategory did not fire because "%s" did not result in a valid category.', $name));
return true;
}
$journal->categories()->detach();
// set category on transactions:
/** @var Transaction $transaction */

View File

@@ -100,7 +100,12 @@ class SetSourceAccount implements ActionInterface
// update source transaction with new source account:
// get source transaction:
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
if (null === $transaction) {
Log::error(sprintf('Cannot change source account of journal #%d because no source transaction exists.', $journal->id));
return false;
}
$transaction->account_id = $this->newSourceAccount->id;
$transaction->save();
$journal->touch();
@@ -130,7 +135,7 @@ class SetSourceAccount implements ActionInterface
/**
*
*/
private function findRevenueAccount()
private function findRevenueAccount(): void
{
$account = $this->repository->findByName($this->action->action_value, [AccountType::REVENUE]);
if (null === $account) {

View File

@@ -52,7 +52,7 @@ class TriggerFactory
*
* @throws FireflyException
*/
public static function getTrigger(RuleTrigger $trigger)
public static function getTrigger(RuleTrigger $trigger): AbstractTrigger
{
$triggerType = $trigger->trigger_type;
@@ -84,7 +84,7 @@ class TriggerFactory
*
* @throws FireflyException
*/
public static function makeTriggerFromStrings(string $triggerType, string $triggerValue, bool $stopProcessing)
public static function makeTriggerFromStrings(string $triggerType, string $triggerValue, bool $stopProcessing): AbstractTrigger
{
/** @var AbstractTrigger $class */
$class = self::getTriggerClass($triggerType);

View File

@@ -72,8 +72,9 @@ final class Processor
* @return Processor
* @throws \FireflyIII\Exceptions\FireflyException
*/
public static function make(Rule $rule, $includeActions = true)
public static function make(Rule $rule, bool $includeActions = null): Processor
{
$includeActions = $includeActions ?? true;
Log::debug(sprintf('Making new rule from Rule %d', $rule->id));
Log::debug(sprintf('Rule is strict: %s', var_export($rule->strict, true)));
$self = new self;
@@ -85,7 +86,7 @@ final class Processor
Log::debug(sprintf('Push trigger %d', $trigger->id));
$self->triggers->push(TriggerFactory::getTrigger($trigger));
}
if ($includeActions) {
if ($includeActions === true) {
$self->actions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
}
@@ -104,7 +105,7 @@ final class Processor
*
* @throws \FireflyIII\Exceptions\FireflyException
*/
public static function makeFromString(string $triggerName, string $triggerValue)
public static function makeFromString(string $triggerName, string $triggerValue): Processor
{
Log::debug(sprintf('Processor::makeFromString("%s", "%s")', $triggerName, $triggerValue));
$self = new self;
@@ -129,7 +130,7 @@ final class Processor
*
* @throws \FireflyIII\Exceptions\FireflyException
*/
public static function makeFromStringArray(array $triggers)
public static function makeFromStringArray(array $triggers): Processor
{
$self = new self;
foreach ($triggers as $entry) {
@@ -156,7 +157,7 @@ final class Processor
*
* @param int $foundTriggers
*/
public function setFoundTriggers(int $foundTriggers)
public function setFoundTriggers(int $foundTriggers): void
{
$this->foundTriggers = $foundTriggers;
}
@@ -236,10 +237,10 @@ final class Processor
/**
* Run the actions
*
* @return bool
* @return void
* @throws \FireflyIII\Exceptions\FireflyException
*/
private function actions()
private function actions(): void
{
/**
* @var int
@@ -255,8 +256,6 @@ final class Processor
break;
}
}
return true;
}
/**

View File

@@ -72,7 +72,7 @@ class AbstractTrigger
*
* @return AbstractTrigger
*/
public static function makeFromTrigger(RuleTrigger $trigger)
public static function makeFromTrigger(RuleTrigger $trigger): AbstractTrigger
{
$self = new static;
$self->trigger = $trigger;
@@ -91,7 +91,7 @@ class AbstractTrigger
*
* @return AbstractTrigger
*/
public static function makeFromTriggerValue(string $triggerValue)
public static function makeFromTriggerValue(string $triggerValue): AbstractTrigger
{
$self = new static;
$self->triggerValue = $triggerValue;

View File

@@ -74,7 +74,7 @@ final class NotesContain extends AbstractTrigger implements TriggerInterface
{
$search = strtolower(trim($this->triggerValue));
if (0 === \strlen($search)) {
if ('' === $search) {
Log::debug(sprintf('RuleTrigger NotesContain for journal #%d: "%s" is empty, return false.', $journal->id, $search));
return false;

View File

@@ -68,7 +68,7 @@ final class NotesEmpty extends AbstractTrigger implements TriggerInterface
$text = $note->text;
}
if (0 === \strlen($text)) {
if ('' === $text) {
Log::debug(sprintf('RuleTrigger NotesEmpty for journal #%d: strlen is 0, return true.', $journal->id));
return true;