2026-09-01 18:54:47 +02:00
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Domain\Jobcard;
|
|
|
|
|
|
|
|
|
|
final class StatusTransitionValidator
|
|
|
|
|
{
|
|
|
|
|
public const STATUSES = ['new', 'assigned', 'in_progress', 'awaiting_client', 'awaiting_parts', 'completed', 'closed'];
|
|
|
|
|
|
|
|
|
|
private const TRANSITIONS = [
|
|
|
|
|
'new' => ['assigned'],
|
|
|
|
|
'assigned' => ['in_progress'],
|
|
|
|
|
'in_progress' => ['awaiting_client', 'awaiting_parts', 'completed'],
|
|
|
|
|
'awaiting_client' => ['in_progress', 'completed'],
|
|
|
|
|
'awaiting_parts' => ['in_progress', 'completed'],
|
|
|
|
|
'completed' => ['closed'],
|
2026-09-01 23:42:42 +02:00
|
|
|
'closed' => ['in_progress'],
|
2026-09-01 18:54:47 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function canTransition(string $from, string $to): bool
|
|
|
|
|
{
|
|
|
|
|
return in_array($from, self::STATUSES, true)
|
|
|
|
|
&& in_array($to, self::STATUSES, true)
|
|
|
|
|
&& ($from === $to || in_array($to, self::TRANSITIONS[$from], true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function allowedFrom(string $from): array
|
|
|
|
|
{
|
|
|
|
|
return in_array($from, self::STATUSES, true) ? array_merge([$from], self::TRANSITIONS[$from]) : [];
|
|
|
|
|
}
|
|
|
|
|
}
|