Add no duplicate edges rule for workflow validation

[MAILPOET-4629]
This commit is contained in:
Jan Jakes
2022-09-14 15:11:59 +02:00
committed by David Remer
parent 11a711e42c
commit 325418e826
2 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
<?php declare(strict_types = 1);
namespace MailPoet\Automation\Engine\Validation\WorkflowRules;
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 NoDuplicateEdgesRule implements WorkflowNodeVisitor {
public function initialize(Workflow $workflow): void {
}
public function visitNode(Workflow $workflow, WorkflowNode $node): void {
$visitedNextStepIdsMap = [];
foreach ($node->getStep()->getNextSteps() as $nextStep) {
if (isset($visitedNextStepIdsMap[$nextStep->getId()])) {
throw Exceptions::workflowStructureNotValid(__('Duplicate next step definition found', 'mailpoet'));
}
$visitedNextStepIdsMap[$nextStep->getId()] = true;
}
}
public function complete(Workflow $workflow): void {
}
}