GenerationStatus.php

Code Hygiene Score: 100

Keine Issues gefunden.

Klassen 1

Funktionen 8

Verwendet von 2

Code

<?php

declare(strict_types=1);

namespace Domain\ValueObject;

// @responsibility: Generation-Status-Enum mit State-Machine für Content-Generierung

enum GenerationStatus: string
{
    case IDLE = 'idle';
    case QUEUED = 'queued';
    case GENERATING = 'generating';
    case COMPLETED = 'completed';
    case FAILED = 'failed';

    /**
     * Check if transition to target status is allowed.
     */
    public function canTransitionTo(self $target): bool
    {
        return in_array($target, $this->getAllowedTransitions(), true);
    }

    /**
     * Get all allowed transitions from current status.
     *
     * @return array<self>
     */
    public function getAllowedTransitions(): array
    {
        return match ($this) {
            self::IDLE => [self::QUEUED],
            self::QUEUED => [self::GENERATING, self::FAILED],
            self::GENERATING => [self::COMPLETED, self::FAILED],
            self::COMPLETED => [self::IDLE],
            self::FAILED => [self::IDLE, self::QUEUED],
        };
    }

    /**
     * Check if generation is currently active.
     */
    public function isActive(): bool
    {
        return in_array($this, [self::QUEUED, self::GENERATING], true);
    }

    /**
     * Check if this is a terminal status.
     */
    public function isTerminal(): bool
    {
        return in_array($this, [self::COMPLETED, self::FAILED], true);
    }

    /**
     * Check if generation can be started.
     */
    public function canStart(): bool
    {
        return $this === self::IDLE;
    }

    /**
     * Check if generation can be retried.
     */
    public function canRetry(): bool
    {
        return $this === self::FAILED;
    }

    /**
     * Get human-readable label.
     */
    public function label(): string
    {
        return match ($this) {
            self::IDLE => 'Bereit',
            self::QUEUED => 'In Warteschlange',
            self::GENERATING => 'Wird generiert',
            self::COMPLETED => 'Abgeschlossen',
            self::FAILED => 'Fehlgeschlagen',
        };
    }

    /**
     * Get CSS class for badge styling.
     */
    public function badgeClass(): string
    {
        return match ($this) {
            self::IDLE => 'secondary',
            self::QUEUED => 'pending',
            self::GENERATING => 'info',
            self::COMPLETED => 'completed',
            self::FAILED => 'failed',
        };
    }
}
← Übersicht Graph