mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code cleanup
This commit is contained in:
@@ -22,8 +22,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use FireflyIII\Factory\TagFactory;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
@@ -55,8 +55,16 @@ 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]);
|
||||
/** @var TagFactory $factory */
|
||||
$factory = app(TagFactory::class);
|
||||
$factory->setUser($journal->user);
|
||||
$tag = $factory->findOrCreate($this->action->action_value);
|
||||
if (null === $tag) {
|
||||
// could not find, could not create tag.
|
||||
Log::error(sprintf('RuleAction AddTag. Could not find or create tag "%s"', $this->action->action_value));
|
||||
|
||||
return false;
|
||||
}
|
||||
$count = $journal->tags()->where('tag_id', $tag->id)->count();
|
||||
if (0 === $count) {
|
||||
$journal->tags()->save($tag);
|
||||
|
@@ -51,8 +51,7 @@ class ClearNotes implements ActionInterface
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
|
@@ -92,7 +92,7 @@ class ActionFactory
|
||||
*/
|
||||
protected static function getActionTypes(): array
|
||||
{
|
||||
if (0 === count(self::$actionTypes)) {
|
||||
if (0 === \count(self::$actionTypes)) {
|
||||
self::$actionTypes = Domain::getRuleActions();
|
||||
}
|
||||
|
||||
|
@@ -62,7 +62,7 @@ class TriggerFactory
|
||||
$obj->stopProcessing = $trigger->stop_processing;
|
||||
|
||||
Log::debug(sprintf('self::getTriggerClass("%s") = "%s"', $triggerType, $class));
|
||||
Log::debug(sprintf('%s::makeFromTriggerValue(%s) = object of class "%s"', $class, $trigger->trigger_value, get_class($obj)));
|
||||
Log::debug(sprintf('%s::makeFromTriggerValue(%s) = object of class "%s"', $class, $trigger->trigger_value, \get_class($obj)));
|
||||
|
||||
return $obj;
|
||||
}
|
||||
@@ -101,7 +101,7 @@ class TriggerFactory
|
||||
*/
|
||||
protected static function getTriggerTypes(): array
|
||||
{
|
||||
if (0 === count(self::$triggerTypes)) {
|
||||
if (0 === \count(self::$triggerTypes)) {
|
||||
self::$triggerTypes = Domain::getRuleTriggers();
|
||||
}
|
||||
|
||||
|
@@ -247,7 +247,7 @@ final class Processor
|
||||
foreach ($this->actions as $action) {
|
||||
/** @var ActionInterface $actionClass */
|
||||
$actionClass = ActionFactory::getAction($action);
|
||||
Log::debug(sprintf('Fire action %s on journal #%d', get_class($actionClass), $this->journal->id));
|
||||
Log::debug(sprintf('Fire action %s on journal #%d', \get_class($actionClass), $this->journal->id));
|
||||
$actionClass->act($this->journal);
|
||||
if ($action->stop_processing) {
|
||||
Log::debug('Stop processing now and break.');
|
||||
@@ -273,7 +273,7 @@ final class Processor
|
||||
/** @var AbstractTrigger $trigger */
|
||||
foreach ($this->triggers as $trigger) {
|
||||
++$foundTriggers;
|
||||
Log::debug(sprintf('Now checking trigger %s with value %s', get_class($trigger), $trigger->getTriggerValue()));
|
||||
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!');
|
||||
|
@@ -217,7 +217,6 @@ class TransactionMatcher
|
||||
* @param Processor $processor
|
||||
*
|
||||
* @return Collection
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function runProcessor(Processor $processor): Collection
|
||||
{
|
||||
@@ -276,7 +275,7 @@ class TransactionMatcher
|
||||
|
||||
// Update counters
|
||||
++$page;
|
||||
$processed += count($set);
|
||||
$processed += \count($set);
|
||||
|
||||
Log::debug(sprintf('Page is now %d, processed is %d', $page, $processed));
|
||||
|
||||
|
@@ -72,9 +72,9 @@ final class DescriptionEnds extends AbstractTrigger implements TriggerInterface
|
||||
public function triggered(TransactionJournal $journal): bool
|
||||
{
|
||||
$description = strtolower($journal->description ?? '');
|
||||
$descriptionLength = strlen($description);
|
||||
$descriptionLength = \strlen($description);
|
||||
$search = strtolower($this->triggerValue);
|
||||
$searchLength = strlen($search);
|
||||
$searchLength = \strlen($search);
|
||||
|
||||
// if the string to search for is longer than the description,
|
||||
// return false.
|
||||
|
@@ -74,7 +74,7 @@ final class DescriptionStarts extends AbstractTrigger implements TriggerInterfac
|
||||
$description = strtolower($journal->description ?? '');
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
$part = substr($description, 0, strlen($search));
|
||||
$part = substr($description, 0, \strlen($search));
|
||||
|
||||
if ($part === $search) {
|
||||
Log::debug(sprintf('RuleTrigger DescriptionStarts for journal #%d: "%s" starts with "%s", return true.', $journal->id, $description, $search));
|
||||
|
@@ -78,9 +78,9 @@ final class FromAccountEnds extends AbstractTrigger implements TriggerInterface
|
||||
$name .= strtolower($account->name);
|
||||
}
|
||||
|
||||
$nameLength = strlen($name);
|
||||
$nameLength = \strlen($name);
|
||||
$search = strtolower($this->triggerValue);
|
||||
$searchLength = strlen($search);
|
||||
$searchLength = \strlen($search);
|
||||
|
||||
// if the string to search for is longer than the account name,
|
||||
// it will never be in the account name.
|
||||
|
@@ -79,7 +79,7 @@ final class FromAccountStarts extends AbstractTrigger implements TriggerInterfac
|
||||
}
|
||||
|
||||
$search = strtolower($this->triggerValue);
|
||||
$part = substr($name, 0, strlen($search));
|
||||
$part = substr($name, 0, \strlen($search));
|
||||
|
||||
if ($part === $search) {
|
||||
Log::debug(sprintf('RuleTrigger FromAccountStarts for journal #%d: "%s" starts with "%s", return true.', $journal->id, $name, $search));
|
||||
|
@@ -68,7 +68,7 @@ final class NotesAny extends AbstractTrigger implements TriggerInterface
|
||||
$text = $note->text;
|
||||
}
|
||||
|
||||
if (strlen($text) > 0) {
|
||||
if (\strlen($text) > 0) {
|
||||
Log::debug(sprintf('RuleTrigger NotesEmpty for journal #%d: strlen > 0, return true.', $journal->id));
|
||||
|
||||
return true;
|
||||
|
@@ -75,7 +75,7 @@ final class NotesAre extends AbstractTrigger implements TriggerInterface
|
||||
}
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
if ($text === $search && strlen($text) > 0) {
|
||||
if ($text === $search && \strlen($text) > 0) {
|
||||
Log::debug(sprintf('RuleTrigger NotesAre for journal #%d: "%s" is "%s", return true.', $journal->id, $text, $search));
|
||||
|
||||
return true;
|
||||
|
@@ -74,7 +74,7 @@ final class NotesContain extends AbstractTrigger implements TriggerInterface
|
||||
{
|
||||
$search = strtolower(trim($this->triggerValue));
|
||||
|
||||
if (0 === strlen($search)) {
|
||||
if (0 === \strlen($search)) {
|
||||
Log::debug(sprintf('RuleTrigger NotesContain for journal #%d: "%s" is empty, return false.', $journal->id, $search));
|
||||
|
||||
return false;
|
||||
|
@@ -68,7 +68,7 @@ final class NotesEmpty extends AbstractTrigger implements TriggerInterface
|
||||
$text = $note->text;
|
||||
}
|
||||
|
||||
if (0 === strlen($text)) {
|
||||
if (0 === \strlen($text)) {
|
||||
Log::debug(sprintf('RuleTrigger NotesEmpty for journal #%d: strlen is 0, return true.', $journal->id));
|
||||
|
||||
return true;
|
||||
|
@@ -78,9 +78,9 @@ final class NotesEnd extends AbstractTrigger implements TriggerInterface
|
||||
if (null !== $note) {
|
||||
$text = strtolower($note->text);
|
||||
}
|
||||
$notesLength = strlen($text);
|
||||
$notesLength = \strlen($text);
|
||||
$search = strtolower($this->triggerValue);
|
||||
$searchLength = strlen($search);
|
||||
$searchLength = \strlen($search);
|
||||
|
||||
// if the string to search for is longer than the description,
|
||||
// return false
|
||||
|
@@ -80,7 +80,7 @@ final class NotesStart extends AbstractTrigger implements TriggerInterface
|
||||
}
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
$part = substr($text, 0, strlen($search));
|
||||
$part = substr($text, 0, \strlen($search));
|
||||
|
||||
if ($part === $search) {
|
||||
Log::debug(sprintf('RuleTrigger NotesStart for journal #%d: "%s" starts with "%s", return true.', $journal->id, $text, $search));
|
||||
|
@@ -78,9 +78,9 @@ final class ToAccountEnds extends AbstractTrigger implements TriggerInterface
|
||||
$toAccountName .= strtolower($account->name);
|
||||
}
|
||||
|
||||
$toAccountNameLength = strlen($toAccountName);
|
||||
$toAccountNameLength = \strlen($toAccountName);
|
||||
$search = strtolower($this->triggerValue);
|
||||
$searchLength = strlen($search);
|
||||
$searchLength = \strlen($search);
|
||||
|
||||
// if the string to search for is longer than the account name,
|
||||
// return false
|
||||
|
@@ -79,7 +79,7 @@ final class ToAccountStarts extends AbstractTrigger implements TriggerInterface
|
||||
}
|
||||
|
||||
$search = strtolower($this->triggerValue);
|
||||
$part = substr($toAccountName, 0, strlen($search));
|
||||
$part = substr($toAccountName, 0, \strlen($search));
|
||||
|
||||
if ($part === $search) {
|
||||
Log::debug(sprintf('RuleTrigger ToAccountStarts for journal #%d: "%s" starts with "%s", return true.', $journal->id, $toAccountName, $search));
|
||||
|
Reference in New Issue
Block a user