AtLeastOneTriggerRule.php
3 years ago
ConsistentStepMapRule.php
3 years ago
NoCycleRule.php
2 years ago
NoDuplicateEdgesRule.php
2 years ago
NoJoinRule.php
2 years ago
NoUnreachableStepsRule.php
2 years ago
TriggerNeedsToBeFollowedByActionRule.php
2 years ago
TriggersUnderRootRule.php
2 years ago
UnknownStepRule.php
3 years ago
ValidStepArgsRule.php
3 years ago
ValidStepFiltersRule.php
2 years ago
ValidStepOrderRule.php
3 years ago
ValidStepRule.php
2 months ago
ValidStepValidationRule.php
3 years ago
index.php
3 years ago
NoJoinRule.php
38 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Engine\Validation\AutomationRules; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Automation\Engine\Data\Automation; |
| 9 | use MailPoet\Automation\Engine\Data\Step; |
| 10 | use MailPoet\Automation\Engine\Exceptions; |
| 11 | use MailPoet\Automation\Engine\Validation\AutomationGraph\AutomationNode; |
| 12 | use MailPoet\Automation\Engine\Validation\AutomationGraph\AutomationNodeVisitor; |
| 13 | |
| 14 | class NoJoinRule implements AutomationNodeVisitor { |
| 15 | public const RULE_ID = 'no-join'; |
| 16 | |
| 17 | /** @var array<string|int, Step[]> */ |
| 18 | private $directParentMap = []; |
| 19 | |
| 20 | public function initialize(Automation $automation): void { |
| 21 | $this->directParentMap = []; |
| 22 | } |
| 23 | |
| 24 | public function visitNode(Automation $automation, AutomationNode $node): void { |
| 25 | $step = $node->getStep(); |
| 26 | foreach ($step->getNextStepIds() as $nextStepId) { |
| 27 | $this->directParentMap[$nextStepId] = array_merge($this->directParentMap[$nextStepId] ?? [], [$step]); |
| 28 | } |
| 29 | |
| 30 | if (count($this->directParentMap[$step->getId()] ?? []) > 1) { |
| 31 | throw Exceptions::automationStructureNotValid(__('Path join found in automation graph', 'mailpoet'), self::RULE_ID); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | public function complete(Automation $automation): void { |
| 36 | } |
| 37 | } |
| 38 |