Collect all step error types instead of terminating on the first one

[MAILPOET-4659]
This commit is contained in:
Jan Jakes
2022-10-06 10:02:53 +02:00
committed by Jan Jakeš
parent 04ca19296b
commit a82896e794
7 changed files with 188 additions and 58 deletions

View File

@ -13,9 +13,6 @@ class ValidStepOrderRule implements WorkflowNodeVisitor {
/** @var Registry */
private $registry;
/** @var array<string, array{step_id: string, message: string}> */
private $errors = [];
public function __construct(
Registry $registry
) {
@ -23,7 +20,6 @@ class ValidStepOrderRule implements WorkflowNodeVisitor {
}
public function initialize(Workflow $workflow): void {
$this->errors = [];
}
public function visitNode(Workflow $workflow, WorkflowNode $node): void {
@ -51,22 +47,11 @@ class ValidStepOrderRule implements WorkflowNodeVisitor {
$subjectKeys = $this->collectSubjectKeys($workflow, $node->getParents());
$missingSubjectKeys = array_diff($requiredSubjectKeys, $subjectKeys);
if (count($missingSubjectKeys) > 0) {
$missingKeysString = implode(', ', $missingSubjectKeys);
$this->errors[$step->getId()] = [
'step_id' => $step->getId(),
'message' => sprintf(
// translators: %s are the missing subject keys.
__("Missing required subjects with keys: %s", 'mailpoet'),
$missingKeysString
),
];
throw Exceptions::missingRequiredSubjects($step, $missingSubjectKeys);
}
}
public function complete(Workflow $workflow): void {
if ($this->errors) {
throw Exceptions::workflowNotValid(__('Some steps are not valid', 'mailpoet'), $this->errors);
}
}
/**