Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/Abstracts/AbstractTransitionSuccessJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct(
public StateableModelContract&Model $model,
public string $from,
public string $to,
/** @var array<string, mixed> */
public array $parameters = []) {}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/ArFlowService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace AuroraWebSoftware\ArFlow;

use AuroraWebSoftware\ArFlow\Exceptions\StateNotFoundException;
use AuroraWebSoftware\ArFlow\Exceptions\WorkflowNotFoundException;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Config;

class ArFlowService
{
/** @var array<string, array{states: array<string>, initial_state: string, transitions?: array<string, array{from: string|array<string>, to: string|array<string>, guards?: array<array{0: class-string, 1?: array<string, mixed>}>, actions?: array<array{0: class-string, 1?: array<string, mixed>}>, success_metadata?: array<string, mixed>, success_jobs?: array<array{0: class-string, 1?: array<string, mixed>}>}>}> */
private array $workflows;

public function __construct()
Expand All @@ -21,18 +21,20 @@ public function __construct()
* @return array<string>
*
* @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<class-string>
*/
public function getSupportedModelTypes(string $workflow): array
{
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Collections/TransitionGuardResultCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Collection;

/**
* @extends Collection<string, TransitionGuardResultCollection<TransitionGuardResultDTO>>
* @extends Collection<string, Collection<int, TransitionGuardResultDTO>>
*/
class TransitionGuardResultCollection extends Collection
{
Expand Down
9 changes: 9 additions & 0 deletions src/Contacts/StateableModelContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,42 @@ public function currentState(): string;
public function currentStateMetadata(): array;

/**
* @param array<class-string>|null $withoutGuards
* @return TransitionGuardResultCollection<string, Collection<int, TransitionGuardResultDTO>>
*
* @throws WorkflowNotFoundException
*/
public function transitionGuardResults(string $toState, ?array $withoutGuards = null): TransitionGuardResultCollection;

/**
* @param array<class-string>|null $withoutGuards
*/
public function canTransitionTo(string $toState, ?array $withoutGuards = null): bool;

/**
* @param array<class-string>|null $withoutGuards
* @return array<string>|null
*/
public function definedTransitionKeys(?array $withoutGuards = null): ?array;

/**
* @param array<class-string>|null $withoutGuards
* @return array<string>|null
*
* @throws WorkflowNotFoundException
* @throws Throwable
*/
public function allowedTransitionKeys(?array $withoutGuards = null): ?array;

/**
* @param array<class-string>|null $withoutGuards
* @return array<string>|null
*/
public function definedTransitionStates(?array $withoutGuards = null): ?array;

/**
* @param array<class-string>|null $withoutGuards
* @return array<string>|null
*
* @throws WorkflowNotFoundException
* @throws Throwable
Expand All @@ -108,6 +116,7 @@ public function lastUpdatedTime(): ?DateTime;
/**
* @param class-string|null $actorModelType
* @param array<class-string>|null $withoutGuards
* @param array<string, mixed>|null $metadata
*
* @throws StateNotFoundException
* @throws TransitionActionException
Expand Down
3 changes: 3 additions & 0 deletions src/Contacts/TransitionActionContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

interface TransitionActionContract
{
/**
* @param array<string, mixed> $parameters
*/
public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters = []): void;

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Contacts/TransitionGuardContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

interface TransitionGuardContract
{
/**
* @param array<string, mixed> $parameters
*/
public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters): void;

/**
Expand Down
1 change: 1 addition & 0 deletions src/StateTransition.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class StateTransition extends Model

public string $comment;

/** @var array<string, mixed> */
public array $metadata;

public int $model_id;
Expand Down
3 changes: 3 additions & 0 deletions src/Traits/HasState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/TransitionActions/LogHistoryTransitionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class LogHistoryTransitionAction implements TransitionActionContract
{
/** @var array<string, mixed> */
private array $parameters;

private StateableModelContract&Model $model;
Expand All @@ -17,6 +18,9 @@ class LogHistoryTransitionAction implements TransitionActionContract

private string $to;

/**
* @param array<string, mixed> $parameters
*/
public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters = []): void
{
$this->model = $model;
Expand Down
4 changes: 4 additions & 0 deletions tests/TransitionActions/TestSuccessTransitionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

class TestSuccessTransitionAction implements TransitionActionContract
{
/** @var array<string, mixed> */
public array $parameters;

/**
* @param array<string, mixed> $parameters
*/
public function boot(StateableModelContract&Model $model, string $from, string $to, array $parameters = []): void
{
$this->parameters = $parameters;
Expand Down