Avoid iteration

[MAILPOET-4700]
This commit is contained in:
David Remer
2022-10-24 15:01:15 +03:00
committed by Jan Jakeš
parent 900faa2a71
commit 2cacb5809d

View File

@@ -2,6 +2,7 @@
namespace MailPoet\Automation\Engine\Validation\WorkflowRules; namespace MailPoet\Automation\Engine\Validation\WorkflowRules;
use MailPoet\Automation\Engine\Data\Step;
use MailPoet\Automation\Engine\Data\Workflow; use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Exceptions; use MailPoet\Automation\Engine\Exceptions;
use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowNode; use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowNode;
@@ -10,19 +11,23 @@ use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowNodeVisitor;
class AtLeastOneTriggerRule implements WorkflowNodeVisitor { class AtLeastOneTriggerRule implements WorkflowNodeVisitor {
public const RULE_ID = 'at-least-one-trigger'; public const RULE_ID = 'at-least-one-trigger';
public function initialize(Workflow $workflow): void { /** @var bool */
foreach ($workflow->getSteps() as $step) { private $triggerFound = false;
if ($step->getType() === 'trigger') {
return;
}
}
throw Exceptions::workflowStructureNotValid(__('There must be at least one trigger in the workflow.', 'mailpoet'), self::RULE_ID); public function initialize(Workflow $workflow): void {
$this->triggerFound = false;
} }
public function visitNode(Workflow $workflow, WorkflowNode $node): void { public function visitNode(Workflow $workflow, WorkflowNode $node): void {
if ($node->getStep()->getType() === Step::TYPE_TRIGGER) {
$this->triggerFound = true;
}
} }
public function complete(Workflow $workflow): void { public function complete(Workflow $workflow): void {
if ($this->triggerFound) {
return;
}
throw Exceptions::workflowStructureNotValid(__('There must be at least one trigger in the workflow.', 'mailpoet'), self::RULE_ID);
} }
} }