88 * This exception indicates issues with the workflow structure,
99 * missing required fields, or invalid configuration values.
1010 */
11- class InvalidWorkflowDefinitionException extends WorkflowException
11+ final class InvalidWorkflowDefinitionException extends WorkflowException
1212{
1313 /**
1414 * Create a new invalid workflow definition exception.
@@ -86,7 +86,7 @@ public function getSuggestions(): array
8686 */
8787 public static function missingRequiredField (string $ fieldName , array $ definition ): static
8888 {
89- return new static (
89+ return new self (
9090 "Required field ' {$ fieldName }' is missing from workflow definition " ,
9191 $ definition ,
9292 ["Missing required field: {$ fieldName }" ]
@@ -102,7 +102,7 @@ public static function missingRequiredField(string $fieldName, array $definition
102102 */
103103 public static function invalidStep (string $ stepId , string $ reason , array $ definition ): static
104104 {
105- return new static (
105+ return new self (
106106 "Step ' {$ stepId }' has invalid configuration: {$ reason }" ,
107107 $ definition ,
108108 ["Invalid step ' {$ stepId }': {$ reason }" ]
@@ -116,10 +116,10 @@ public static function invalidStep(string $stepId, string $reason, array $defini
116116 */
117117 public static function invalidStepId (string $ stepId ): static
118118 {
119- return new static (
119+ return new self (
120120 message: "Invalid step ID: ' {$ stepId }'. Step ID cannot be empty. " ,
121- context : ['provided_step_id ' => $ stepId ],
122- suggestions : [
121+ definition : ['provided_step_id ' => $ stepId ],
122+ validationErrors : [
123123 'Use a descriptive step identifier ' ,
124124 'Examples: "send_email", "validate_input", "process_payment" ' ,
125125 'Ensure the step ID is not empty or whitespace-only ' ,
@@ -134,10 +134,10 @@ public static function invalidStepId(string $stepId): static
134134 */
135135 public static function invalidRetryAttempts (int $ attempts ): static
136136 {
137- return new static (
137+ return new self (
138138 message: "Invalid retry attempts: {$ attempts }. Must be between 0 and 10. " ,
139- context : ['provided_attempts ' => $ attempts , 'valid_range ' => '0-10 ' ],
140- suggestions : [
139+ definition : ['provided_attempts ' => $ attempts , 'valid_range ' => '0-10 ' ],
140+ validationErrors : [
141141 'Use a value between 0 and 10 for retry attempts ' ,
142142 'Consider 0 for no retries, 3 for moderate resilience, or 5+ for critical operations ' ,
143143 'Too many retries can delay workflow completion significantly ' ,
@@ -152,10 +152,10 @@ public static function invalidRetryAttempts(int $attempts): static
152152 */
153153 public static function invalidTimeout (?int $ timeout ): static
154154 {
155- return new static (
155+ return new self (
156156 message: "Invalid timeout: {$ timeout }. Timeout must be a positive integer or null. " ,
157- context : ['provided_timeout ' => $ timeout ],
158- suggestions : [
157+ definition : ['provided_timeout ' => $ timeout ],
158+ validationErrors : [
159159 'Use a positive integer for timeout in seconds ' ,
160160 'Use null for no timeout limit ' ,
161161 'Consider reasonable timeouts: 30s for quick operations, 300s for complex tasks ' ,
@@ -170,10 +170,10 @@ public static function invalidTimeout(?int $timeout): static
170170 */
171171 public static function duplicateStepId (string $ stepId ): static
172172 {
173- return new static (
173+ return new self (
174174 message: "Duplicate step ID: ' {$ stepId }'. Step IDs must be unique within a workflow. " ,
175- context : ['duplicate_step_id ' => $ stepId ],
176- suggestions : [
175+ definition : ['duplicate_step_id ' => $ stepId ],
176+ validationErrors : [
177177 'Use unique step identifiers within each workflow ' ,
178178 'Consider adding prefixes or suffixes to make IDs unique ' ,
179179 'Examples: "send_email_1", "send_email_welcome", "send_email_reminder" ' ,
@@ -201,14 +201,14 @@ public static function invalidName(string $name, ?string $reason = null): static
201201 'Examples: "user-onboarding", "order_processing", "documentApproval" ' ,
202202 ];
203203
204- return new static (
204+ return new self (
205205 message: $ message ,
206- context : [
206+ definition : [
207207 'provided_name ' => $ name ,
208208 'validation_rule ' => '/^[a-zA-Z][a-zA-Z0-9_-]*$/ ' ,
209209 'reason ' => $ reason ,
210210 ],
211- suggestions : $ suggestions
211+ validationErrors : $ suggestions
212212 );
213213 }
214214
@@ -219,10 +219,10 @@ public static function invalidName(string $name, ?string $reason = null): static
219219 */
220220 public static function invalidCondition (string $ condition ): static
221221 {
222- return new static (
222+ return new self (
223223 message: "Invalid condition expression: ' {$ condition }'. Condition cannot be empty. " ,
224- context : ['provided_condition ' => $ condition ],
225- suggestions : [
224+ definition : ['provided_condition ' => $ condition ],
225+ validationErrors : [
226226 'Use valid condition expressions with comparison operators ' ,
227227 'Examples: "user.premium === true", "order.amount > 1000", "status !== \'cancelled \'" ' ,
228228 'Supported operators: ===, !==, ==, !=, >, <, >=, <= ' ,
@@ -240,14 +240,14 @@ public static function invalidCondition(string $condition): static
240240 */
241241 public static function invalidDelay (?int $ seconds , ?int $ minutes , ?int $ hours ): static
242242 {
243- return new static (
243+ return new self (
244244 message: 'Invalid delay configuration. At least one positive time value must be provided. ' ,
245- context : [
245+ definition : [
246246 'provided_seconds ' => $ seconds ,
247247 'provided_minutes ' => $ minutes ,
248248 'provided_hours ' => $ hours ,
249249 ],
250- suggestions : [
250+ validationErrors : [
251251 'Provide at least one positive time value ' ,
252252 'Examples: delay(seconds: 30), delay(minutes: 5), delay(hours: 1) ' ,
253253 'You can combine multiple time units: delay(hours: 1, minutes: 30) ' ,
@@ -263,10 +263,10 @@ public static function invalidDelay(?int $seconds, ?int $minutes, ?int $hours):
263263 */
264264 public static function emptyWorkflow (string $ workflowName ): static
265265 {
266- return new static (
266+ return new self (
267267 message: "Workflow ' {$ workflowName }' cannot be built with no steps defined. " ,
268- context : ['workflow_name ' => $ workflowName ],
269- suggestions : [
268+ definition : ['workflow_name ' => $ workflowName ],
269+ validationErrors : [
270270 'Add at least one step using addStep(), startWith(), or then() methods ' ,
271271 'Example: $builder->addStep("validate", ValidateAction::class) ' ,
272272 'Consider using common patterns: email(), delay(), or http() ' ,
@@ -307,10 +307,10 @@ public static function actionNotFound(string $actionName, array $context = []):
307307 $ suggestions [] = $ context ['suggestion ' ];
308308 }
309309
310- return new static (
310+ return new self (
311311 message: $ message ,
312- context : array_merge (['action_name ' => $ actionName ], $ context ),
313- suggestions : $ suggestions
312+ definition : array_merge (['action_name ' => $ actionName ], $ context ),
313+ validationErrors : $ suggestions
314314 );
315315 }
316316
@@ -322,15 +322,15 @@ public static function actionNotFound(string $actionName, array $context = []):
322322 */
323323 public static function invalidActionClass (string $ className , string $ requiredInterface ): static
324324 {
325- return new static (
325+ return new self (
326326 message: "Class ' {$ className }' does not implement the required ' {$ requiredInterface }' interface. " ,
327- context : [
327+ definition : [
328328 'class_name ' => $ className ,
329329 'required_interface ' => $ requiredInterface ,
330330 'class_exists ' => class_exists ($ className ),
331331 'implemented_interfaces ' => class_exists ($ className ) ? class_implements ($ className ) : [],
332332 ],
333- suggestions : [
333+ validationErrors : [
334334 "Make sure ' {$ className }' implements the ' {$ requiredInterface }' interface " ,
335335 'Check that the class has the required methods: execute(), canExecute(), getName(), getDescription() ' ,
336336 'Verify the class is properly imported and autoloaded ' ,
0 commit comments