Skip to content

Commit 67eaad5

Browse files
committed
Merge commit '9fc62f12cd21271a72500fa02fbd4efa2713c537'
# Conflicts: # src/Actions/ConditionAction.php # src/Core/WorkflowBuilder.php # src/Core/WorkflowContext.php # src/Core/WorkflowState.php # src/Examples/ModernWorkflowExamples.php # src/Support/SimpleWorkflow.php
2 parents 166de46 + 9fc62f1 commit 67eaad5

11 files changed

+69
-67
lines changed

src/Core/ActionResult.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
* @see WorkflowAction For the interface that returns ActionResult
7272
* @see BaseAction For the base implementation using ActionResult
7373
*/
74-
class ActionResult
74+
final class ActionResult
7575
{
7676
/**
7777
* Create a new action result.
@@ -117,7 +117,7 @@ public function __construct(
117117
*/
118118
public static function success(array $data = [], array $metadata = []): static
119119
{
120-
return new static(true, null, $data, $metadata);
120+
return new self(true, null, $data, $metadata);
121121
}
122122

123123
/**
@@ -149,7 +149,7 @@ public static function success(array $data = [], array $metadata = []): static
149149
*/
150150
public static function failure(string $errorMessage, array $metadata = []): static
151151
{
152-
return new static(false, $errorMessage, [], $metadata);
152+
return new self(false, $errorMessage, [], $metadata);
153153
}
154154

155155
/**
@@ -290,7 +290,7 @@ public function getMetadata(): array
290290
*/
291291
public function withMetadata(array $metadata): static
292292
{
293-
return new static(
293+
return new self(
294294
$this->success,
295295
$this->errorMessage,
296296
$this->data,

src/Core/WorkflowBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* @see WorkflowDefinition For the resulting workflow definition structure
4747
* @see QuickWorkflowBuilder For pre-built common workflow patterns
4848
*/
49-
class WorkflowBuilder
49+
final class WorkflowBuilder
5050
{
5151
/** @var string The unique workflow name/identifier */
5252
private string $name;
@@ -101,7 +101,7 @@ private function __construct(string $name)
101101
*/
102102
public static function create(string $name): static
103103
{
104-
return new static($name);
104+
return new self($name);
105105
}
106106

107107
/**

src/Core/WorkflowContext.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* @see WorkflowInstance For workflow execution state management
4747
* @see WorkflowEngine For workflow execution coordination
4848
*/
49-
readonly class WorkflowContext
49+
final readonly class WorkflowContext
5050
{
5151
/**
5252
* Create a new immutable workflow context.
@@ -128,7 +128,7 @@ public function getAllData(): array
128128
*/
129129
public function withData(array $newData): static
130130
{
131-
return new static(
131+
return new self(
132132
workflowId: $this->workflowId,
133133
stepId: $this->stepId,
134134
data: array_merge($this->data, $newData),
@@ -158,7 +158,7 @@ public function with(string $key, mixed $value): static
158158
$newData = $this->data;
159159
data_set($newData, $key, $value);
160160

161-
return new static(
161+
return new self(
162162
workflowId: $this->workflowId,
163163
stepId: $this->stepId,
164164
data: $newData,

src/Core/WorkflowDefinition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* @see WorkflowBuilder For fluent workflow construction
5252
* @see WorkflowEngine For workflow execution
5353
*/
54-
class WorkflowDefinition
54+
final class WorkflowDefinition
5555
{
5656
/** @var array<string, Step> Indexed steps for fast lookup by ID */
5757
private readonly array $steps;
@@ -386,7 +386,7 @@ public function toArray(): array
386386
*/
387387
public static function fromArray(array $data): static
388388
{
389-
return new static(
389+
return new self(
390390
name: $data['name'],
391391
version: $data['version'] ?? '1.0',
392392
steps: $data['steps'] ?? [],

src/Core/WorkflowInstance.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
* @see WorkflowState For execution state enumeration
9191
* @see WorkflowContext For step execution context
9292
*/
93-
class WorkflowInstance
93+
final class WorkflowInstance
9494
{
9595
/** @var WorkflowState Current execution state of the workflow */
9696
private WorkflowState $state;
@@ -399,7 +399,7 @@ public function toArray(): array
399399
*/
400400
public static function fromArray(array $data, WorkflowDefinition $definition): static
401401
{
402-
$instance = new static(
402+
$instance = new self(
403403
id: $data['id'],
404404
definition: $definition,
405405
state: WorkflowState::from($data['state']),

src/Exceptions/ActionNotFoundException.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* This exception provides detailed guidance for resolving action-related
1212
* issues including class loading, dependency injection, and interface compliance.
1313
*/
14-
class ActionNotFoundException extends WorkflowException
14+
final class ActionNotFoundException extends WorkflowException
1515
{
1616
/**
1717
* Create a new action not found exception.
@@ -153,7 +153,7 @@ public static function actionNotFound(
153153
Step $step,
154154
WorkflowContext $context
155155
): static {
156-
return new static($actionClass, $step->getId(), 'action_not_found');
156+
return new self($actionClass, $step->getId(), 'action_not_found');
157157
}
158158

159159
/**
@@ -168,7 +168,7 @@ public static function invalidActionClass(
168168
Step $step,
169169
WorkflowContext $context
170170
): static {
171-
return new static($actionClass, $step->getId(), 'invalid_action_class');
171+
return new self($actionClass, $step->getId(), 'invalid_action_class');
172172
}
173173

174174
/**
@@ -183,7 +183,7 @@ public static function classNotFound(
183183
Step $step,
184184
WorkflowContext $context
185185
): static {
186-
return new static($actionClass, $step->getId(), 'class_not_found');
186+
return new self($actionClass, $step->getId(), 'class_not_found');
187187
}
188188

189189
/**
@@ -198,6 +198,6 @@ public static function invalidInterface(
198198
Step $step,
199199
WorkflowContext $context
200200
): static {
201-
return new static($actionClass, $step->getId(), 'invalid_interface');
201+
return new self($actionClass, $step->getId(), 'invalid_interface');
202202
}
203203
}

src/Exceptions/InvalidWorkflowDefinitionException.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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',

src/Exceptions/InvalidWorkflowStateException.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* This exception helps developers understand workflow lifecycle rules
1212
* and provides clear guidance on valid state transitions.
1313
*/
14-
class InvalidWorkflowStateException extends WorkflowException
14+
final class InvalidWorkflowStateException extends WorkflowException
1515
{
1616
/**
1717
* Create a new invalid workflow state exception.
@@ -152,7 +152,7 @@ public function getSuggestions(): array
152152
*/
153153
public static function cannotResumeCompleted(string $instanceId): static
154154
{
155-
return new static(
155+
return new self(
156156
"Cannot resume workflow '{$instanceId}' because it is already completed",
157157
WorkflowState::COMPLETED,
158158
WorkflowState::RUNNING,
@@ -167,7 +167,7 @@ public static function cannotResumeCompleted(string $instanceId): static
167167
*/
168168
public static function cannotCancelFailed(string $instanceId): static
169169
{
170-
return new static(
170+
return new self(
171171
"Cannot cancel workflow '{$instanceId}' because it has already failed",
172172
WorkflowState::FAILED,
173173
WorkflowState::CANCELLED,
@@ -182,7 +182,7 @@ public static function cannotCancelFailed(string $instanceId): static
182182
*/
183183
public static function alreadyRunning(string $instanceId): static
184184
{
185-
return new static(
185+
return new self(
186186
"Cannot start workflow '{$instanceId}' because it is already running",
187187
WorkflowState::RUNNING,
188188
WorkflowState::RUNNING,
@@ -204,7 +204,7 @@ public static function fromInstanceTransition(
204204
): static {
205205
$message = "Cannot {$operation} workflow '{$instance->getId()}' - invalid state transition";
206206

207-
return new static(
207+
return new self(
208208
$message,
209209
$instance->getState(),
210210
$attemptedState,

0 commit comments

Comments
 (0)