Code clean up.

This commit is contained in:
James Cole
2017-11-15 12:25:49 +01:00
parent 57dcdfa0c4
commit ffca858b8d
476 changed files with 2055 additions and 4181 deletions

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -27,9 +26,7 @@ use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
/**
* Interface ActionInterface
*
* @package FireflyIII\TransactionRules\Action
* Interface ActionInterface.
*/
interface ActionInterface
{

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -29,13 +28,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class AddTag
*
* @package FireflyIII\TransactionRules\Actions
* Class AddTag.
*/
class AddTag implements ActionInterface
{
/** @var RuleAction */
private $action;
@@ -56,12 +52,11 @@ class AddTag implements ActionInterface
*/
public function act(TransactionJournal $journal): bool
{
// journal has this tag maybe?
$tag = Tag::firstOrCreateEncrypted(['tag' => $this->action->action_value, 'user_id' => $journal->user->id]);
$count = $journal->tags()->where('tag_id', $tag->id)->count();
if ($count === 0) {
if (0 === $count) {
$journal->tags()->save($tag);
Log::debug(sprintf('RuleAction AddTag. Added tag #%d ("%s") to journal %d.', $tag->id, $tag->tag, $journal->id));

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class AppendDescription
*
* @package FireflyIII\TransactionRules\Actions
* Class AppendDescription.
*/
class AppendDescription implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class AppendNotes
*
* @package FireflyIII\TransactionRules\Actions
* Class AppendNotes.
*/
class AppendNotes implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*
@@ -56,7 +52,7 @@ class AppendNotes implements ActionInterface
public function act(TransactionJournal $journal): bool
{
$dbNote = $journal->notes()->first();
if (is_null($dbNote)) {
if (null === $dbNote) {
$dbNote = new Note;
$dbNote->noteable()->associate($journal);
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class ClearBudget
*
* @package FireflyIII\TransactionRules\Action
* Class ClearBudget.
*/
class ClearBudget implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class ClearCategory
*
* @package FireflyIII\TransactionRules\Action
* Class ClearCategory.
*/
class ClearCategory implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class ClearNotes
*
* @package FireflyIII\TransactionRules\Actions
* Class ClearNotes.
*/
class ClearNotes implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class AppendDescription
*
* @package FireflyIII\TransactionRules\Actions
* Class AppendDescription.
*/
class PrependDescription implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*
@@ -58,7 +54,6 @@ class PrependDescription implements ActionInterface
$journal->description = $this->action->action_value . $journal->description;
$journal->save();
return true;
}
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class PrependNotes
*
* @package FireflyIII\TransactionRules\Actions
* Class PrependNotes.
*/
class PrependNotes implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*
@@ -56,7 +52,7 @@ class PrependNotes implements ActionInterface
public function act(TransactionJournal $journal): bool
{
$dbNote = $journal->notes()->first();
if (is_null($dbNote)) {
if (null === $dbNote) {
$dbNote = new Note;
$dbNote->noteable()->associate($journal);
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class RemoveAllTags
*
* @package FireflyIII\TransactionRules\Actions
* Class RemoveAllTags.
*/
class RemoveAllTags implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class RemoveTag
*
* @package FireflyIII\TransactionRules\Actions
* Class RemoveTag.
*/
class RemoveTag implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*
@@ -64,7 +60,7 @@ class RemoveTag implements ActionInterface
}
)->first();
if (!is_null($tag)) {
if (null !== $tag) {
Log::debug(sprintf('RuleAction RemoveTag removed tag #%d ("%s") from journal #%d.', $tag->id, $tag->tag, $journal->id));
$journal->tags()->detach([$tag->id]);

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -31,15 +30,12 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Log;
/**
* Class SetBudget
*
* @package FireflyIII\TransactionRules\Action
* Class SetBudget.
*/
class SetBudget implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*
@@ -67,13 +63,13 @@ class SetBudget implements ActionInterface
return $current->name === $search;
}
)->first();
if (is_null($budget)) {
if (null === $budget) {
Log::debug(sprintf('RuleAction SetBudget could not set budget of journal #%d to "%s" because no such budget exists.', $journal->id, $search));
return true;
}
if ($journal->transactionType->type !== TransactionType::WITHDRAWAL) {
if (TransactionType::WITHDRAWAL !== $journal->transactionType->type) {
Log::debug(
sprintf(
'RuleAction SetBudget could not set budget of journal #%d to "%s" because journal is a %s.',
@@ -90,7 +86,6 @@ class SetBudget implements ActionInterface
$journal->budgets()->sync([$budget->id]);
return true;
}
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class SetCategory
*
* @package FireflyIII\TransactionRules\Action
* Class SetCategory.
*/
class SetCategory implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class SetDescription
*
* @package FireflyIII\TransactionRules\Actions
* Class SetDescription.
*/
class SetDescription implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -32,24 +31,21 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Log;
/**
* Class SetDestinationAccount
*
* @package FireflyIII\TransactionRules\Action
* Class SetDestinationAccount.
*/
class SetDestinationAccount implements ActionInterface
{
private $action;
/** @var TransactionJournal */
/** @var TransactionJournal */
private $journal;
/** @var Account */
/** @var Account */
private $newDestinationAccount;
/** @var AccountRepositoryInterface */
private $repository;
/**
* TriggerInterface constructor.
*
@@ -81,7 +77,7 @@ class SetDestinationAccount implements ActionInterface
$type = $journal->transactionType->type;
// if this is a deposit or a transfer, the destination account must be an asset account or a default account, and it MUST exist:
if (($type === TransactionType::DEPOSIT || $type === TransactionType::TRANSFER) && !$this->findAssetAccount()) {
if ((TransactionType::DEPOSIT === $type || TransactionType::TRANSFER === $type) && !$this->findAssetAccount()) {
Log::error(
sprintf(
'Cannot change destination account of journal #%d because no asset account with name "%s" exists.',
@@ -94,7 +90,7 @@ class SetDestinationAccount implements ActionInterface
}
// if this is a withdrawal, the new destination account must be a expense account and may be created:
if ($type === TransactionType::WITHDRAWAL) {
if (TransactionType::WITHDRAWAL === $type) {
$this->findExpenseAccount();
}
@@ -117,7 +113,7 @@ class SetDestinationAccount implements ActionInterface
{
$account = $this->repository->findByName($this->action->action_value, [AccountType::DEFAULT, AccountType::ASSET]);
if (is_null($account->id)) {
if (null === $account->id) {
Log::debug(sprintf('There is NO asset account called "%s".', $this->action->action_value));
return false;
@@ -134,7 +130,7 @@ class SetDestinationAccount implements ActionInterface
private function findExpenseAccount()
{
$account = $this->repository->findByName($this->action->action_value, [AccountType::EXPENSE]);
if (is_null($account->id)) {
if (null === $account->id) {
// create new revenue account with this name:
$data = [
'name' => $this->action->action_value,

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class SetNotes
*
* @package FireflyIII\TransactionRules\Actions
* Class SetNotes.
*/
class SetNotes implements ActionInterface
{
private $action;
/**
* TriggerInterface constructor.
*
@@ -56,7 +52,7 @@ class SetNotes implements ActionInterface
public function act(TransactionJournal $journal): bool
{
$dbNote = $journal->notes()->first();
if (is_null($dbNote)) {
if (null === $dbNote) {
$dbNote = new Note;
$dbNote->noteable()->associate($journal);
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
@@ -32,24 +31,21 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Log;
/**
* Class SetSourceAccount
*
* @package FireflyIII\TransactionRules\Action
* Class SetSourceAccount.
*/
class SetSourceAccount implements ActionInterface
{
private $action;
/** @var TransactionJournal */
/** @var TransactionJournal */
private $journal;
/** @var Account */
/** @var Account */
private $newSourceAccount;
/** @var AccountRepositoryInterface */
private $repository;
/**
* TriggerInterface constructor.
*
@@ -80,7 +76,7 @@ class SetSourceAccount implements ActionInterface
// journal type:
$type = $journal->transactionType->type;
// if this is a transfer or a withdrawal, the new source account must be an asset account or a default account, and it MUST exist:
if (($type === TransactionType::WITHDRAWAL || $type === TransactionType::TRANSFER) && !$this->findAssetAccount()) {
if ((TransactionType::WITHDRAWAL === $type || TransactionType::TRANSFER === $type) && !$this->findAssetAccount()) {
Log::error(
sprintf(
'Cannot change source account of journal #%d because no asset account with name "%s" exists.',
@@ -93,7 +89,7 @@ class SetSourceAccount implements ActionInterface
}
// if this is a deposit, the new source account must be a revenue account and may be created:
if ($type === TransactionType::DEPOSIT) {
if (TransactionType::DEPOSIT === $type) {
$this->findRevenueAccount();
}
@@ -116,7 +112,7 @@ class SetSourceAccount implements ActionInterface
{
$account = $this->repository->findByName($this->action->action_value, [AccountType::DEFAULT, AccountType::ASSET]);
if (is_null($account->id)) {
if (null === $account->id) {
Log::debug(sprintf('There is NO asset account called "%s".', $this->action->action_value));
return false;
@@ -133,7 +129,7 @@ class SetSourceAccount implements ActionInterface
private function findRevenueAccount()
{
$account = $this->repository->findByName($this->action->action_value, [AccountType::REVENUE]);
if (is_null($account->id)) {
if (null === $account->id) {
// create new revenue account with this name:
$data = [
'name' => $this->action->action_value,

View File

@@ -1,7 +1,7 @@
<?php
/**
* ActionFactory.php
* Copyright (C) 2016 Robert Horlings
* Copyright (C) 2016 Robert Horlings.
*
* This file is part of Firefly III.
*
@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Factory;
@@ -32,8 +31,6 @@ use Log;
/**
* @codeCoverageIgnore
* Class ActionFactory
*
* @package FireflyIII\TransactionRules\Factory
*/
class ActionFactory
{
@@ -65,6 +62,7 @@ class ActionFactory
* @param string $actionType
*
* @return string
*
* @throws FireflyException
*/
public static function getActionClass(string $actionType): string
@@ -84,13 +82,13 @@ class ActionFactory
}
/**
* Returns a map with actiontypes, mapped to the class representing that type
* Returns a map with actiontypes, mapped to the class representing that type.
*
* @return array
*/
protected static function getActionTypes(): array
{
if (count(self::$actionTypes) === 0) {
if (0 === count(self::$actionTypes)) {
self::$actionTypes = Domain::getRuleActions();
}

View File

@@ -1,7 +1,7 @@
<?php
/**
* TriggerFactory.php
* Copyright (C) 2016 Robert Horlings
* Copyright (C) 2016 Robert Horlings.
*
* This file is part of Firefly III.
*
@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Factory;
@@ -33,8 +32,6 @@ use Log;
/**
* @codeCoverageIgnore
* Interface TriggerInterface
*
* @package FireflyIII\TransactionRules\Triggers
*/
class TriggerFactory
{
@@ -78,7 +75,9 @@ class TriggerFactory
* @param bool $stopProcessing
*
* @see TriggerFactory::getTrigger
*
* @return AbstractTrigger
*
* @throws FireflyException
*/
public static function makeTriggerFromStrings(string $triggerType, string $triggerValue, bool $stopProcessing)
@@ -98,7 +97,7 @@ class TriggerFactory
*/
protected static function getTriggerTypes(): array
{
if (count(self::$triggerTypes) === 0) {
if (0 === count(self::$triggerTypes)) {
self::$triggerTypes = Domain::getRuleTriggers();
}
@@ -113,6 +112,7 @@ class TriggerFactory
* @param string $triggerType
*
* @return TriggerInterface|string
*
* @throws FireflyException
*/
private static function getTriggerClass(string $triggerType): string

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules;
@@ -36,26 +35,23 @@ use Illuminate\Support\Collection;
use Log;
/**
* Class Processor
*
* @package FireflyIII\TransactionRules
* Class Processor.
*/
final class Processor
{
/** @var Collection */
/** @var Collection */
public $actions;
/** @var TransactionJournal */
/** @var TransactionJournal */
public $journal;
/** @var Rule */
/** @var Rule */
public $rule;
/** @var Collection */
public $triggers;
/** @var int */
protected $foundTriggers = 0;
private $foundTriggers = 0;
/**
* Processor constructor.
*
*/
private function __construct()
{
@@ -68,7 +64,6 @@ final class Processor
* and actions found in the given Rule.
*
* @param Rule $rule
*
* @param bool $includeActions
*
* @return Processor
@@ -128,7 +123,7 @@ final class Processor
{
$self = new self;
foreach ($triggers as $entry) {
$entry['value'] = is_null($entry['value']) ? '' : $entry['value'];
$entry['value'] = null === $entry['value'] ? '' : $entry['value'];
$trigger = TriggerFactory::makeTriggerFromStrings($entry['type'], $entry['value'], $entry['stopProcessing']);
$self->triggers->push($trigger);
}
@@ -153,7 +148,6 @@ final class Processor
}
/**
*
* @return \FireflyIII\Models\Rule
*/
public function getRule(): Rule
@@ -185,7 +179,7 @@ final class Processor
Log::debug('Has more than zero actions.');
$this->actions();
}
if ($this->actions->count() === 0) {
if (0 === $this->actions->count()) {
Log::info('Rule has no actions!');
}
@@ -227,7 +221,7 @@ final class Processor
private function actions()
{
/**
* @var int $index
* @var int
* @var RuleAction $action
*/
foreach ($this->actions as $action) {
@@ -246,7 +240,7 @@ final class Processor
/**
* Method to check whether the current transaction would be triggered
* by the given list of triggers
* by the given list of triggers.
*
* @return bool
*/
@@ -258,12 +252,12 @@ final class Processor
Log::debug(sprintf('Found triggers starts at %d', $foundTriggers));
/** @var AbstractTrigger $trigger */
foreach ($this->triggers as $trigger) {
$foundTriggers++;
++$foundTriggers;
Log::debug(sprintf('Now checking trigger %s with value %s', get_class($trigger), $trigger->getTriggerValue()));
/** @var AbstractTrigger $trigger */
if ($trigger->triggered($this->journal)) {
Log::debug('Is a match!');
$hitTriggers++;
++$hitTriggers;
}
if ($trigger->stopProcessing) {
Log::debug('Stop processing this trigger and break.');

View File

@@ -1,7 +1,7 @@
<?php
/**
* TransactionMatcher.php
* Copyright (C) 2016 Robert Horlings
* Copyright (C) 2016 Robert Horlings.
*
* This file is part of Firefly III.
*
@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules;
@@ -33,9 +32,7 @@ use Log;
/**
* Class TransactionMatcher is used to find a list of
* transaction matching a set of triggers
*
* @package FireflyIII\TransactionRules
* transaction matching a set of triggers.
*/
class TransactionMatcher
{
@@ -43,9 +40,9 @@ class TransactionMatcher
private $limit = 10;
/** @var int Maximum number of transaction to search in (for performance reasons) * */
private $range = 200;
/** @var Rule */
/** @var Rule */
private $rule;
/** @var JournalTaskerInterface */
/** @var JournalTaskerInterface */
private $tasker;
/** @var array */
private $transactionTypes = [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
@@ -68,11 +65,10 @@ class TransactionMatcher
* triggers onto each transaction journal until enough matches are found ($limit).
*
* @return Collection
*
*/
public function findTransactionsByRule()
{
if (count($this->rule->ruleTriggers) === 0) {
if (0 === count($this->rule->ruleTriggers)) {
return new Collection;
}
@@ -93,11 +89,10 @@ class TransactionMatcher
* triggers onto each transaction journal until enough matches are found ($limit).
*
* @return Collection
*
*/
public function findTransactionsByTriggers(): Collection
{
if (count($this->triggers) === 0) {
if (0 === count($this->triggers)) {
return new Collection;
}
@@ -125,7 +120,7 @@ class TransactionMatcher
*
* @return TransactionMatcher
*/
public function setLimit(int $limit): TransactionMatcher
public function setLimit(int $limit): self
{
$this->limit = $limit;
@@ -145,7 +140,7 @@ class TransactionMatcher
*
* @return TransactionMatcher
*/
public function setRange(int $range): TransactionMatcher
public function setRange(int $range): self
{
$this->range = $range;
@@ -165,7 +160,7 @@ class TransactionMatcher
*
* @return TransactionMatcher
*/
public function setTriggers(array $triggers): TransactionMatcher
public function setTriggers(array $triggers): self
{
$this->triggers = $triggers;
@@ -221,7 +216,7 @@ class TransactionMatcher
Log::debug(sprintf('Total count is now %d', $result->count()));
// Update counters
$page++;
++$page;
$processed += count($set);
Log::debug(sprintf('Page is now %d, processed is %d', $page, $processed));

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -30,20 +29,18 @@ use FireflyIII\Models\TransactionJournal;
* This class will be magical!
*
* Class AbstractTrigger
*
* @package FireflyIII\TransactionRules\Triggers
*/
class AbstractTrigger
{
/** @var bool */
/** @var bool */
public $stopProcessing;
/** @var string */
/** @var string */
protected $checkValue;
/** @var TransactionJournal */
/** @var TransactionJournal */
protected $journal;
/** @var RuleTrigger */
protected $trigger;
/** @var string */
/** @var string */
protected $triggerValue;
/**
@@ -106,6 +103,7 @@ class AbstractTrigger
/**
* @codeCoverageIgnore
*
* @return RuleTrigger
*/
public function getTrigger(): RuleTrigger
@@ -115,6 +113,7 @@ class AbstractTrigger
/**
* @codeCoverageIgnore
*
* @return string
*/
public function getTriggerValue(): string

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -27,13 +26,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class AmountExactly
*
* @package FireflyIII\TransactionRules\Triggers
* Class AmountExactly.
*/
final class AmountExactly extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -52,7 +48,7 @@ final class AmountExactly extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
if (null !== $value) {
return false;
}
Log::error(sprintf('Cannot use %s with a null value.', self::class));
@@ -70,7 +66,7 @@ final class AmountExactly extends AbstractTrigger implements TriggerInterface
$amount = $journal->destination_amount ?? $journal->amountPositive();
$compare = $this->triggerValue;
$result = bccomp($amount, $compare);
if ($result === 0) {
if (0 === $result) {
Log::debug(sprintf('RuleTrigger AmountExactly for journal #%d: %d matches %d exactly, so return true', $journal->id, $amount, $compare));
return true;

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -27,13 +26,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class AmountLess
*
* @package FireflyIII\TransactionRules\Triggers
* Class AmountLess.
*/
final class AmountLess extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -52,7 +48,7 @@ final class AmountLess extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
if (null !== $value) {
return false;
}
Log::error(sprintf('Cannot use %s with a null value.', self::class));

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -27,13 +26,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class AmountMore
*
* @package FireflyIII\TransactionRules\Triggers
* Class AmountMore.
*/
final class AmountMore extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -52,9 +48,9 @@ final class AmountMore extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = bccomp('0', strval($value)) === 0;
if ($res === true) {
if (null !== $value) {
$res = 0 === bccomp('0', strval($value));
if (true === $res) {
Log::error(sprintf('Cannot use %s with a value equal to 0.', self::class));
}
@@ -76,7 +72,7 @@ final class AmountMore extends AbstractTrigger implements TriggerInterface
$amount = $journal->destination_amount ?? $journal->amountPositive();
$compare = $this->triggerValue;
$result = bccomp($amount, $compare);
if ($result === 1) {
if (1 === $result) {
Log::debug(sprintf('RuleTrigger AmountMore for journal #%d: %d is more than %d, so return true', $journal->id, $amount, $compare));
return true;

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class BudgetIs
*
* @package FireflyIII\TransactionRules\Triggers
* Class BudgetIs.
*/
final class BudgetIs extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,7 +49,7 @@ final class BudgetIs extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
if (null !== $value) {
return false;
}
Log::error(sprintf('Cannot use %s with a null value.', self::class));
@@ -69,7 +65,7 @@ final class BudgetIs extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal): bool
{
$budget = $journal->budgets()->first();
if (!is_null($budget)) {
if (null !== $budget) {
$name = strtolower($budget->name);
// match on journal:
if ($name === strtolower($this->triggerValue)) {
@@ -79,12 +75,12 @@ final class BudgetIs extends AbstractTrigger implements TriggerInterface
}
}
if (is_null($budget)) {
if (null === $budget) {
// perhaps transactions have this budget?
/** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) {
$budget = $transaction->budgets()->first();
if (!is_null($budget)) {
if (null !== $budget) {
$name = strtolower($budget->name);
if ($name === strtolower($this->triggerValue)) {
Log::debug(

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class CategoryIs
*
* @package FireflyIII\TransactionRules\Triggers
* Class CategoryIs.
*/
final class CategoryIs extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,7 +49,7 @@ final class CategoryIs extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
if (null !== $value) {
return false;
}
Log::error(sprintf('Cannot use %s with a null value.', self::class));
@@ -69,7 +65,7 @@ final class CategoryIs extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal): bool
{
$category = $journal->categories()->first();
if (!is_null($category)) {
if (null !== $category) {
$name = strtolower($category->name);
// match on journal:
if ($name === strtolower($this->triggerValue)) {
@@ -79,12 +75,12 @@ final class CategoryIs extends AbstractTrigger implements TriggerInterface
}
}
if (is_null($category)) {
if (null === $category) {
// perhaps transactions have this category?
/** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) {
$category = $transaction->categories()->first();
if (!is_null($category)) {
if (null !== $category) {
$name = strtolower($category->name);
if ($name === strtolower($this->triggerValue)) {
Log::debug(

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -27,13 +26,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class DescriptionContains
*
* @package FireflyIII\TransactionRules\Triggers
* Class DescriptionContains.
*/
final class DescriptionContains extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -52,9 +48,9 @@ final class DescriptionContains extends AbstractTrigger implements TriggerInterf
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}
@@ -76,7 +72,7 @@ final class DescriptionContains extends AbstractTrigger implements TriggerInterf
$search = strtolower($this->triggerValue);
$source = strtolower($journal->description ?? '');
$strpos = stripos($source, $search);
if (!($strpos === false)) {
if (!(false === $strpos)) {
Log::debug(sprintf('RuleTrigger DescriptionContains for journal #%d: "%s" contains "%s", return true.', $journal->id, $source, $search));
return true;

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -27,13 +26,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class DescriptionEnds
*
* @package FireflyIII\TransactionRules\Triggers
* Class DescriptionEnds.
*/
final class DescriptionEnds extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -52,9 +48,9 @@ final class DescriptionEnds extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -27,13 +26,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class DescriptionIs
*
* @package FireflyIII\TransactionRules\Triggers
* Class DescriptionIs.
*/
final class DescriptionIs extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -52,7 +48,7 @@ final class DescriptionIs extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
if (null !== $value) {
return false;
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -27,13 +26,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class DescriptionStarts
*
* @package FireflyIII\TransactionRules\Triggers
* Class DescriptionStarts.
*/
final class DescriptionStarts extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -52,9 +48,9 @@ final class DescriptionStarts extends AbstractTrigger implements TriggerInterfac
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class FromAccountContains
*
* @package FireflyIII\TransactionRules\Triggers
* Class FromAccountContains.
*/
final class FromAccountContains extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,9 +49,9 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}
@@ -83,7 +79,7 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf
$search = strtolower($this->triggerValue);
$strpos = strpos($fromAccountName, $search);
if (!($strpos === false)) {
if (!(false === $strpos)) {
Log::debug(sprintf('RuleTrigger FromAccountContains for journal #%d: "%s" contains "%s", return true.', $journal->id, $fromAccountName, $search));
return true;

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class FromAccountEnds
*
* @package FireflyIII\TransactionRules\Triggers
* Class FromAccountEnds.
*/
final class FromAccountEnds extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,9 +49,9 @@ final class FromAccountEnds extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}
@@ -92,7 +88,6 @@ final class FromAccountEnds extends AbstractTrigger implements TriggerInterface
return false;
}
$part = substr($name, $searchLength * -1);
if ($part === $search) {

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class FromAccountIs
*
* @package FireflyIII\TransactionRules\Triggers
* Class FromAccountIs.
*/
final class FromAccountIs extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,9 +49,9 @@ final class FromAccountIs extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class FromAccountStarts
*
* @package FireflyIII\TransactionRules\Triggers
* Class FromAccountStarts.
*/
final class FromAccountStarts extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,9 +49,9 @@ final class FromAccountStarts extends AbstractTrigger implements TriggerInterfac
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasAnyBudget
*
* @package FireflyIII\TransactionRules\Triggers
* Class HasAnyBudget.
*/
final class HasAnyBudget extends AbstractTrigger implements TriggerInterface
{
/**
* 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

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasAnyCategory
*
* @package FireflyIII\TransactionRules\Triggers
* Class HasAnyCategory.
*/
final class HasAnyCategory extends AbstractTrigger implements TriggerInterface
{
/**
* 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

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -27,13 +26,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasAnyTag
*
* @package FireflyIII\TransactionRules\Triggers
* Class HasAnyTag.
*/
final class HasAnyTag extends AbstractTrigger implements TriggerInterface
{
/**
* 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

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,7 +27,6 @@ use Log;
class HasAttachment extends AbstractTrigger implements TriggerInterface
{
/**
* 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

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasNoBudget
*
* @package FireflyIII\TransactionRules\Triggers
* Class HasNoBudget.
*/
final class HasNoBudget extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -70,7 +66,7 @@ final class HasNoBudget extends AbstractTrigger implements TriggerInterface
foreach ($journal->transactions()->get() as $transaction) {
$count += $transaction->budgets()->count();
}
if ($count === 0) {
if (0 === $count) {
Log::debug(sprintf('RuleTrigger HasNoBudget for journal #%d: count is %d, return true.', $journal->id, $count));
return true;

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasNoCategory
*
* @package FireflyIII\TransactionRules\Triggers
* Class HasNoCategory.
*/
final class HasNoCategory extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -71,7 +67,7 @@ final class HasNoCategory extends AbstractTrigger implements TriggerInterface
$count += $transaction->categories()->count();
}
if ($count === 0) {
if (0 === $count) {
Log::debug(sprintf('RuleTrigger HasNoCategory for journal #%d: count is %d, return true.', $journal->id, $count));
return true;

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -27,13 +26,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasNoTag
*
* @package FireflyIII\TransactionRules\Triggers
* Class HasNoTag.
*/
final class HasNoTag extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -63,7 +59,7 @@ final class HasNoTag extends AbstractTrigger implements TriggerInterface
public function triggered(TransactionJournal $journal): bool
{
$count = $journal->tags()->count();
if ($count === 0) {
if (0 === $count) {
Log::debug(sprintf('RuleTrigger HasNoTag for journal #%d: count is %d, return true.', $journal->id, $count));
return true;

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class NotesAny
*
* @package FireflyIII\TransactionRules\Triggers
* Class NotesAny.
*/
final class NotesAny extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -66,7 +62,7 @@ final class NotesAny extends AbstractTrigger implements TriggerInterface
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
if (null !== $note) {
$text = $note->text;
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class NotesAre
*
* @package FireflyIII\TransactionRules\Triggers
* Class NotesAre.
*/
final class NotesAre extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,7 +49,7 @@ final class NotesAre extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
if (null !== $value) {
return false;
}
@@ -72,7 +68,7 @@ final class NotesAre extends AbstractTrigger implements TriggerInterface
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
if (null !== $note) {
$text = strtolower($note->text);
}
$search = strtolower($this->triggerValue);

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class NotesContain
*
* @package FireflyIII\TransactionRules\Triggers
* Class NotesContain.
*/
final class NotesContain extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,9 +49,9 @@ final class NotesContain extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}
@@ -76,7 +72,7 @@ final class NotesContain extends AbstractTrigger implements TriggerInterface
{
$search = trim(strtolower($this->triggerValue));
if (strlen($search) === 0) {
if (0 === strlen($search)) {
Log::debug(sprintf('RuleTrigger NotesContain for journal #%d: "%s" is empty, return false.', $journal->id, $search));
return false;
@@ -85,13 +81,12 @@ final class NotesContain extends AbstractTrigger implements TriggerInterface
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
if (null !== $note) {
$text = strtolower($note->text);
}
$strpos = strpos($text, $search);
if (!($strpos === false)) {
if (!(false === $strpos)) {
Log::debug(sprintf('RuleTrigger NotesContain for journal #%d: "%s" contains "%s", return true.', $journal->id, $text, $search));
return true;

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class NotesEmpty
*
* @package FireflyIII\TransactionRules\Triggers
* Class NotesEmpty.
*/
final class NotesEmpty extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -66,11 +62,11 @@ final class NotesEmpty extends AbstractTrigger implements TriggerInterface
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
if (null !== $note) {
$text = $note->text;
}
if (strlen($text) === 0) {
if (0 === strlen($text)) {
Log::debug(sprintf('RuleTrigger NotesEmpty for journal #%d: strlen is 0, return true.', $journal->id));
return true;

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class NotesEnd
*
* @package FireflyIII\TransactionRules\Triggers
* Class NotesEnd.
*/
final class NotesEnd extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,9 +49,9 @@ final class NotesEnd extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}
@@ -77,7 +73,7 @@ final class NotesEnd extends AbstractTrigger implements TriggerInterface
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
if (null !== $note) {
$text = strtolower($note->text);
}
$notesLength = strlen($text);

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class NotesStart
*
* @package FireflyIII\TransactionRules\Triggers
* Class NotesStart.
*/
final class NotesStart extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,9 +49,9 @@ final class NotesStart extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}
@@ -77,7 +73,7 @@ final class NotesStart extends AbstractTrigger implements TriggerInterface
/** @var Note $note */
$note = $journal->notes()->first();
$text = '';
if (!is_null($note)) {
if (null !== $note) {
$text = strtolower($note->text);
}
$search = strtolower($this->triggerValue);

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class TagIs
*
* @package FireflyIII\TransactionRules\Triggers
* Class TagIs.
*/
final class TagIs extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,7 +49,7 @@ final class TagIs extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
if (null !== $value) {
return false;
}
Log::error(sprintf('Cannot use %s with a null value.', self::class));

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class ToAccountContains
*
* @package FireflyIII\TransactionRules\Triggers
* Class ToAccountContains.
*/
final class ToAccountContains extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,9 +49,9 @@ final class ToAccountContains extends AbstractTrigger implements TriggerInterfac
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}
@@ -83,7 +79,7 @@ final class ToAccountContains extends AbstractTrigger implements TriggerInterfac
$search = strtolower($this->triggerValue);
$strpos = strpos($toAccountName, $search);
if (!($strpos === false)) {
if (!(false === $strpos)) {
Log::debug(sprintf('RuleTrigger ToAccountContains for journal #%d: "%s" contains "%s", return true.', $journal->id, $toAccountName, $search));
return true;

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class ToAccountEnds
*
* @package FireflyIII\TransactionRules\Triggers
* Class ToAccountEnds.
*/
final class ToAccountEnds extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,9 +49,9 @@ final class ToAccountEnds extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}
@@ -92,7 +88,6 @@ final class ToAccountEnds extends AbstractTrigger implements TriggerInterface
return false;
}
$part = substr($toAccountName, $searchLength * -1);
if ($part === $search) {

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class ToAccountIs
*
* @package FireflyIII\TransactionRules\Triggers
* Class ToAccountIs.
*/
final class ToAccountIs extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,9 +49,9 @@ final class ToAccountIs extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -28,13 +27,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class ToAccountStarts
*
* @package FireflyIII\TransactionRules\Triggers
* Class ToAccountStarts.
*/
final class ToAccountStarts extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -53,9 +49,9 @@ final class ToAccountStarts extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
$res = strval($value) === '';
if ($res === true) {
if (null !== $value) {
$res = '' === strval($value);
if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
}
@@ -90,7 +86,6 @@ final class ToAccountStarts extends AbstractTrigger implements TriggerInterface
}
Log::debug(sprintf('RuleTrigger ToAccountStarts for journal #%d: "%s" does not start with "%s", return false.', $journal->id, $toAccountName, $search));
return false;
}
}

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -27,13 +26,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class TransactionType
*
* @package FireflyIII\TransactionRules\Triggers
* Class TransactionType.
*/
final class TransactionType extends AbstractTrigger implements TriggerInterface
{
/**
* 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
@@ -52,7 +48,7 @@ final class TransactionType extends AbstractTrigger implements TriggerInterface
*/
public static function willMatchEverything($value = null)
{
if (!is_null($value)) {
if (null !== $value) {
return false;
}
Log::error(sprintf('Cannot use %s with a null value.', self::class));
@@ -67,7 +63,7 @@ final class TransactionType extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$type = !is_null($journal->transaction_type_type) ? $journal->transaction_type_type : strtolower($journal->transactionType->type);
$type = null !== $journal->transaction_type_type ? $journal->transaction_type_type : strtolower($journal->transactionType->type);
$search = strtolower($this->triggerValue);
if ($type === $search) {

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -26,13 +25,10 @@ namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\TransactionJournal;
/**
* Interface TriggerInterface
*
* @package FireflyIII\TransactionRules\Triggers
* Interface TriggerInterface.
*/
interface TriggerInterface
{
/**
* 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

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
@@ -27,13 +26,10 @@ use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class UserAction
*
* @package FireflyIII\TransactionRules\Triggers
* Class UserAction.
*/
final class UserAction extends AbstractTrigger implements TriggerInterface
{
/**
* 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