Add no join rule for workflow validation

[MAILPOET-4629]
This commit is contained in:
Jan Jakes
2022-09-14 15:13:10 +02:00
committed by David Remer
parent cafe2ed8a7
commit 65927cc281
2 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,32 @@
<?php declare(strict_types = 1);
namespace MailPoet\Automation\Engine\Validation\WorkflowRules;
use MailPoet\Automation\Engine\Data\Step;
use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Exceptions;
use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowNode;
use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowNodeVisitor;
class NoJoinRule implements WorkflowNodeVisitor {
/** @var array<string, Step> */
private $visitedSteps = [];
public function initialize(Workflow $workflow): void {
$this->visitedSteps = [];
}
public function visitNode(Workflow $workflow, WorkflowNode $node): void {
$step = $node->getStep();
$this->visitedSteps[$step->getId()] = $step;
foreach ($step->getNextSteps() as $nextStep) {
$nextStepId = $nextStep->getId();
if (isset($this->visitedSteps[$nextStepId])) {
throw Exceptions::workflowStructureNotValid(__('Path join found in workflow graph', 'mailpoet'));
}
}
}
public function complete(Workflow $workflow): void {
}
}