mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 09:52:20 +00:00
Fix code quality with rector [skip ci]
This commit is contained in:
@@ -45,9 +45,10 @@ use Illuminate\Support\Facades\Log;
|
||||
class SearchRuleEngine implements RuleEngineInterface
|
||||
{
|
||||
private readonly Collection $groups;
|
||||
private array $operators;
|
||||
private bool $refreshTriggers;
|
||||
private array $resultCount;
|
||||
private array $operators = [];
|
||||
// always collect the triggers from the database, unless indicated otherwise.
|
||||
private bool $refreshTriggers = true;
|
||||
private array $resultCount = [];
|
||||
private readonly Collection $rules;
|
||||
private User $user;
|
||||
|
||||
@@ -55,11 +56,6 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
{
|
||||
$this->rules = new Collection();
|
||||
$this->groups = new Collection();
|
||||
$this->operators = [];
|
||||
$this->resultCount = [];
|
||||
|
||||
// always collect the triggers from the database, unless indicated otherwise.
|
||||
$this->refreshTriggers = true;
|
||||
}
|
||||
|
||||
public function addOperator(array $operator): void
|
||||
@@ -119,7 +115,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
Log::debug(sprintf('SearchRuleEngine:: add a rule trigger (no context): %s:true', $ruleTrigger->trigger_type));
|
||||
$searchArray[$ruleTrigger->trigger_type][] = 'true';
|
||||
}
|
||||
if (true === $needsContext) {
|
||||
if ($needsContext) {
|
||||
Log::debug(sprintf('SearchRuleEngine:: add a rule trigger (context): %s:"%s"', $ruleTrigger->trigger_type, $ruleTrigger->trigger_value));
|
||||
$searchArray[$ruleTrigger->trigger_type][] = sprintf('"%s"', $ruleTrigger->trigger_value);
|
||||
}
|
||||
@@ -288,7 +284,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
|
||||
// make collection unique
|
||||
$unique = $total->unique(
|
||||
static function (array $group) {
|
||||
static function (array $group): string {
|
||||
$str = '';
|
||||
foreach ($group['transactions'] as $transaction) {
|
||||
$str = sprintf('%s%d', $str, $transaction['transaction_journal_id']);
|
||||
@@ -319,7 +315,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
/** @var Rule $rule */
|
||||
foreach ($this->rules as $rule) { // @phpstan-ignore-line
|
||||
$result = $this->fireRule($rule);
|
||||
if (true === $result && true === $rule->stop_processing) {
|
||||
if ($result && true === $rule->stop_processing) {
|
||||
Log::debug(sprintf('Rule #%d has triggered and executed, but calls to stop processing. Since not in the context of a group, do not stop.', $rule->id));
|
||||
}
|
||||
if (false === $result && true === $rule->stop_processing) {
|
||||
@@ -378,7 +374,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
$this->processResults($rule, $collection);
|
||||
|
||||
$result = $collection->count() > 0;
|
||||
if (true === $result) {
|
||||
if ($result) {
|
||||
Log::debug(sprintf('SearchRuleEngine:: Done. Rule #%d was triggered (on %d transaction(s)).', $rule->id, $collection->count()));
|
||||
|
||||
return true;
|
||||
@@ -428,7 +424,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
continue;
|
||||
}
|
||||
$break = $this->processRuleAction($ruleAction, $transaction);
|
||||
if (true === $break) {
|
||||
if ($break) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -444,7 +440,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
$actionClass = ActionFactory::getAction($ruleAction);
|
||||
$result = $actionClass->actOnArray($transaction);
|
||||
$journalId = $transaction['transaction_journal_id'] ?? 0;
|
||||
if (true === $result) {
|
||||
if ($result) {
|
||||
$this->resultCount[$journalId] = array_key_exists($journalId, $this->resultCount) ? $this->resultCount[$journalId]++ : 1;
|
||||
Log::debug(
|
||||
sprintf(
|
||||
@@ -460,7 +456,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
// pick up from the action if it actually acted or not:
|
||||
if (true === $ruleAction->stop_processing && true === $result) {
|
||||
if (true === $ruleAction->stop_processing && $result) {
|
||||
Log::debug(sprintf('Rule action "%s" reports changes AND asks to break, so break!', $ruleAction->action_type));
|
||||
|
||||
return true;
|
||||
@@ -527,7 +523,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
foreach ($rules as $rule) {
|
||||
Log::debug(sprintf('Going to fire rule #%d with order #%d from group #%d', $rule->id, $rule->order, $group->id));
|
||||
$result = $this->fireRule($rule);
|
||||
if (true === $result && true === $rule->stop_processing) {
|
||||
if ($result && true === $rule->stop_processing) {
|
||||
Log::debug(sprintf('The rule was triggered and rule->stop_processing = true, so group #%d will stop processing further rules.', $group->id));
|
||||
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user