'Pending', self::PROCESSING => 'Processing', self::COMPLETED => 'Completed', self::FAILED => 'Failed', self::RETRYING => 'Retrying', self::CANCELLED => 'Cancelled', self::EXPIRED => 'Expired', }; } /** * Check if status represents a final state */ public function isFinal(): bool { return match ($this) { self::COMPLETED, self::CANCELLED, self::EXPIRED => true, default => false }; } /** * Check if status represents an active state */ public function isActive(): bool { return match ($this) { self::PENDING, self::PROCESSING, self::RETRYING => true, default => false }; } /** * Check if status represents a failure state */ public function isFailure(): bool { return match ($this) { self::FAILED, self::EXPIRED => true, default => false }; } /** * Get next possible statuses from current status * * @return self[] */ public function getNextPossibleStatuses(): array { return match ($this) { self::PENDING => [self::PROCESSING, self::CANCELLED], self::PROCESSING => [self::COMPLETED, self::FAILED, self::CANCELLED, self::EXPIRED], self::RETRYING => [self::PROCESSING, self::FAILED, self::CANCELLED], self::FAILED => [self::RETRYING, self::CANCELLED], default => [] // Final states have no transitions }; } /** * Check if transition to another status is valid */ public function canTransitionTo(self $newStatus): bool { return in_array($newStatus, $this->getNextPossibleStatuses(), true); } }