From ad206afbe50527df06d716ab400795109cd3f22e Mon Sep 17 00:00:00 2001 From: Emre Akay Date: Fri, 13 Jun 2025 18:26:02 +0300 Subject: [PATCH 1/3] phpstan --- composer.json | 2 +- src/Abstracts/AbstractTransitionSuccessJob.php | 1 + src/ArFlowService.php | 7 +++++-- src/Collections/TransitionGuardResultCollection.php | 2 +- src/Contacts/StateableModelContract.php | 9 +++++++++ src/Contacts/TransitionActionContract.php | 3 +++ src/Contacts/TransitionGuardContract.php | 3 +++ src/StateTransition.php | 1 + src/Traits/HasState.php | 3 +++ src/TransitionActions/LogHistoryTransitionAction.php | 4 ++++ tests/TransitionActions/TestSuccessTransitionAction.php | 4 ++++ 11 files changed, 35 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 4b6280b..50b74f2 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "@composer run build", "@php vendor/bin/testbench serve" ], - "analyse": "vendor/bin/phpstan analyse", + "analyse": "php -d memory_limit=2G vendor/bin/phpstan analyse --memory-limit=2G", "test": "vendor/bin/pest", "test-coverage": "vendor/bin/pest --coverage", "format": "vendor/bin/pint" diff --git a/src/Abstracts/AbstractTransitionSuccessJob.php b/src/Abstracts/AbstractTransitionSuccessJob.php index f506a5a..a8a5274 100644 --- a/src/Abstracts/AbstractTransitionSuccessJob.php +++ b/src/Abstracts/AbstractTransitionSuccessJob.php @@ -19,6 +19,7 @@ public function __construct( public StateableModelContract&Model $model, public string $from, public string $to, + /** @var array */ public array $parameters = []) {} /** diff --git a/src/ArFlowService.php b/src/ArFlowService.php index 0ebd07e..f071cf2 100755 --- a/src/ArFlowService.php +++ b/src/ArFlowService.php @@ -10,6 +10,7 @@ class ArFlowService { + /** @var array, initial_state: string, transitions?: array, to: string|array, guards?: array}>, actions?: array}>, success_metadata?: array, success_jobs?: array}>}>}> */ private array $workflows; public function __construct() @@ -21,18 +22,20 @@ public function __construct() * @return array * * @throws WorkflowNotFoundException - * @throws StateNotFoundException */ public function getStates(string $workflow): array { foreach ($this->workflows as $workflowKey => $workflowValues) { if ($workflowKey == $workflow) { - return $workflowValues['states'] ?? throw new StateNotFoundException; + return $workflowValues['states']; } } throw new WorkflowNotFoundException; } + /** + * @return array + */ public function getSupportedModelTypes(string $workflow): array { return []; diff --git a/src/Collections/TransitionGuardResultCollection.php b/src/Collections/TransitionGuardResultCollection.php index 4eed45c..90a163c 100644 --- a/src/Collections/TransitionGuardResultCollection.php +++ b/src/Collections/TransitionGuardResultCollection.php @@ -6,7 +6,7 @@ use Illuminate\Support\Collection; /** - * @extends Collection> + * @extends Collection> */ class TransitionGuardResultCollection extends Collection { diff --git a/src/Contacts/StateableModelContract.php b/src/Contacts/StateableModelContract.php index 8431290..a8e9f9a 100644 --- a/src/Contacts/StateableModelContract.php +++ b/src/Contacts/StateableModelContract.php @@ -69,15 +69,20 @@ public function currentState(): string; public function currentStateMetadata(): array; /** + * @param array|null $withoutGuards * @return TransitionGuardResultCollection> * * @throws WorkflowNotFoundException */ public function transitionGuardResults(string $toState, ?array $withoutGuards = null): TransitionGuardResultCollection; + /** + * @param array|null $withoutGuards + */ public function canTransitionTo(string $toState, ?array $withoutGuards = null): bool; /** + * @param array|null $withoutGuards * @return array|null */ public function definedTransitionKeys(?array $withoutGuards = null): ?array; @@ -87,10 +92,12 @@ public function definedTransitionKeys(?array $withoutGuards = null): ?array; * * @throws WorkflowNotFoundException * @throws Throwable + * @return array|null */ public function allowedTransitionKeys(?array $withoutGuards = null): ?array; /** + * @param array|null $withoutGuards * @return array|null */ public function definedTransitionStates(?array $withoutGuards = null): ?array; @@ -100,6 +107,7 @@ public function definedTransitionStates(?array $withoutGuards = null): ?array; * * @throws WorkflowNotFoundException * @throws Throwable + * @return array|null */ public function allowedTransitionStates(?array $withoutGuards = null): ?array; @@ -108,6 +116,7 @@ public function lastUpdatedTime(): ?DateTime; /** * @param class-string|null $actorModelType * @param array|null $withoutGuards + * @param array|null $metadata * * @throws StateNotFoundException * @throws TransitionActionException diff --git a/src/Contacts/TransitionActionContract.php b/src/Contacts/TransitionActionContract.php index 4afec77..35a0b59 100644 --- a/src/Contacts/TransitionActionContract.php +++ b/src/Contacts/TransitionActionContract.php @@ -8,6 +8,9 @@ interface TransitionActionContract { + /** + * @param array $parameters + */ public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters = []): void; /** diff --git a/src/Contacts/TransitionGuardContract.php b/src/Contacts/TransitionGuardContract.php index 09ff810..7553d1e 100644 --- a/src/Contacts/TransitionGuardContract.php +++ b/src/Contacts/TransitionGuardContract.php @@ -9,6 +9,9 @@ interface TransitionGuardContract { + /** + * @param array $parameters + */ public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters): void; /** diff --git a/src/StateTransition.php b/src/StateTransition.php index 6fb3cf1..3f9b499 100644 --- a/src/StateTransition.php +++ b/src/StateTransition.php @@ -22,6 +22,7 @@ class StateTransition extends Model public string $comment; + /** @var array */ public array $metadata; public int $model_id; diff --git a/src/Traits/HasState.php b/src/Traits/HasState.php index 59d040e..538cca3 100644 --- a/src/Traits/HasState.php +++ b/src/Traits/HasState.php @@ -24,6 +24,9 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Config; +/** + * @phpstan-ignore-next-line + */ trait HasState { public function getId(): int|string diff --git a/src/TransitionActions/LogHistoryTransitionAction.php b/src/TransitionActions/LogHistoryTransitionAction.php index 23edf72..c9cf091 100644 --- a/src/TransitionActions/LogHistoryTransitionAction.php +++ b/src/TransitionActions/LogHistoryTransitionAction.php @@ -9,6 +9,7 @@ class LogHistoryTransitionAction implements TransitionActionContract { + /** @var array */ private array $parameters; private StateableModelContract&Model $model; @@ -17,6 +18,9 @@ class LogHistoryTransitionAction implements TransitionActionContract private string $to; + /** + * @param array $parameters + */ public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters = []): void { $this->model = $model; diff --git a/tests/TransitionActions/TestSuccessTransitionAction.php b/tests/TransitionActions/TestSuccessTransitionAction.php index f2367ac..1163c52 100644 --- a/tests/TransitionActions/TestSuccessTransitionAction.php +++ b/tests/TransitionActions/TestSuccessTransitionAction.php @@ -8,8 +8,12 @@ class TestSuccessTransitionAction implements TransitionActionContract { + /** @var array */ public array $parameters; + /** + * @param array $parameters + */ public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters = []): void { $this->parameters = $parameters; From 3500e09fa754e9a303db76e520fa61ac8dbc2c55 Mon Sep 17 00:00:00 2001 From: Emre Akay Date: Fri, 13 Jun 2025 18:30:52 +0300 Subject: [PATCH 2/3] phpstan --- composer.json | 2 +- src/ArFlowService.php | 5 +++-- src/Traits/HasState.php | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 50b74f2..6ba75db 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "@composer run build", "@php vendor/bin/testbench serve" ], - "analyse": "php -d memory_limit=2G vendor/bin/phpstan analyse --memory-limit=2G", + "analyse": "php -d memory_limit=20G vendor/bin/phpstan analyse", "test": "vendor/bin/pest", "test-coverage": "vendor/bin/pest --coverage", "format": "vendor/bin/pint" diff --git a/src/ArFlowService.php b/src/ArFlowService.php index f071cf2..969ce3d 100755 --- a/src/ArFlowService.php +++ b/src/ArFlowService.php @@ -10,7 +10,7 @@ class ArFlowService { - /** @var array, initial_state: string, transitions?: array, to: string|array, guards?: array}>, actions?: array}>, success_metadata?: array, success_jobs?: array}>}>}> */ + /** @var array, initial_state: string, transitions?: array, to: string|array, guards?: array}>, actions?: array}>, success_metadata?: array, success_jobs?: array}>}>}> */ private array $workflows; public function __construct() @@ -22,12 +22,13 @@ public function __construct() * @return array * * @throws WorkflowNotFoundException + * @throws StateNotFoundException */ public function getStates(string $workflow): array { foreach ($this->workflows as $workflowKey => $workflowValues) { if ($workflowKey == $workflow) { - return $workflowValues['states']; + return $workflowValues['states'] ?? throw new StateNotFoundException; } } throw new WorkflowNotFoundException; diff --git a/src/Traits/HasState.php b/src/Traits/HasState.php index 538cca3..7f5f5ff 100644 --- a/src/Traits/HasState.php +++ b/src/Traits/HasState.php @@ -341,6 +341,7 @@ public function lastUpdatedTime(): ?DateTime /** * @param class-string|null $actorModelType * @param array|null $withoutGuards + * @param array|null $metadata * * @throws StateNotFoundException * @throws TransitionActionException From d748be51a3a5e1cb5d4c6b0f3887e8df05ae7a96 Mon Sep 17 00:00:00 2001 From: emreakay Date: Fri, 13 Jun 2025 15:33:21 +0000 Subject: [PATCH 3/3] Fix styling --- src/Contacts/StateableModelContract.php | 12 ++++++------ src/Contacts/TransitionActionContract.php | 2 +- src/Contacts/TransitionGuardContract.php | 2 +- src/TransitionActions/LogHistoryTransitionAction.php | 2 +- .../TestSuccessTransitionAction.php | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Contacts/StateableModelContract.php b/src/Contacts/StateableModelContract.php index a8e9f9a..3204e28 100644 --- a/src/Contacts/StateableModelContract.php +++ b/src/Contacts/StateableModelContract.php @@ -69,7 +69,7 @@ public function currentState(): string; public function currentStateMetadata(): array; /** - * @param array|null $withoutGuards + * @param array|null $withoutGuards * @return TransitionGuardResultCollection> * * @throws WorkflowNotFoundException @@ -77,37 +77,37 @@ public function currentStateMetadata(): array; public function transitionGuardResults(string $toState, ?array $withoutGuards = null): TransitionGuardResultCollection; /** - * @param array|null $withoutGuards + * @param array|null $withoutGuards */ public function canTransitionTo(string $toState, ?array $withoutGuards = null): bool; /** - * @param array|null $withoutGuards + * @param array|null $withoutGuards * @return array|null */ public function definedTransitionKeys(?array $withoutGuards = null): ?array; /** * @param array|null $withoutGuards + * @return array|null * * @throws WorkflowNotFoundException * @throws Throwable - * @return array|null */ public function allowedTransitionKeys(?array $withoutGuards = null): ?array; /** - * @param array|null $withoutGuards + * @param array|null $withoutGuards * @return array|null */ public function definedTransitionStates(?array $withoutGuards = null): ?array; /** * @param array|null $withoutGuards + * @return array|null * * @throws WorkflowNotFoundException * @throws Throwable - * @return array|null */ public function allowedTransitionStates(?array $withoutGuards = null): ?array; diff --git a/src/Contacts/TransitionActionContract.php b/src/Contacts/TransitionActionContract.php index 35a0b59..daff78c 100644 --- a/src/Contacts/TransitionActionContract.php +++ b/src/Contacts/TransitionActionContract.php @@ -9,7 +9,7 @@ interface TransitionActionContract { /** - * @param array $parameters + * @param array $parameters */ public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters = []): void; diff --git a/src/Contacts/TransitionGuardContract.php b/src/Contacts/TransitionGuardContract.php index 7553d1e..23552be 100644 --- a/src/Contacts/TransitionGuardContract.php +++ b/src/Contacts/TransitionGuardContract.php @@ -10,7 +10,7 @@ interface TransitionGuardContract { /** - * @param array $parameters + * @param array $parameters */ public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters): void; diff --git a/src/TransitionActions/LogHistoryTransitionAction.php b/src/TransitionActions/LogHistoryTransitionAction.php index c9cf091..0974909 100644 --- a/src/TransitionActions/LogHistoryTransitionAction.php +++ b/src/TransitionActions/LogHistoryTransitionAction.php @@ -19,7 +19,7 @@ class LogHistoryTransitionAction implements TransitionActionContract private string $to; /** - * @param array $parameters + * @param array $parameters */ public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters = []): void { diff --git a/tests/TransitionActions/TestSuccessTransitionAction.php b/tests/TransitionActions/TestSuccessTransitionAction.php index 1163c52..8b2646c 100644 --- a/tests/TransitionActions/TestSuccessTransitionAction.php +++ b/tests/TransitionActions/TestSuccessTransitionAction.php @@ -12,7 +12,7 @@ class TestSuccessTransitionAction implements TransitionActionContract public array $parameters; /** - * @param array $parameters + * @param array $parameters */ public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters = []): void {