Files
JobcardSystem/app/Domain/Jobcard/StatusTransitionValidator.php
T

32 lines
1.0 KiB
PHP
Raw Normal View History

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'],
'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]) : [];
}
}