PipelineRunStatus.php

Code Hygiene Score: 100

Keine Issues gefunden.

Klassen 1

Funktionen 7

Versionen 1

Code

<?php

declare(strict_types=1);

namespace Domain\ValueObject;

// @responsibility: Pipeline-Run-Status-Enum mit State-Machine

enum PipelineRunStatus: string
{
    case PENDING = 'pending';
    case RUNNING = 'running';
    case COMPLETED = 'completed';
    case FAILED = 'failed';
    case CANCELLED = 'cancelled';

    /**
     * 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::PENDING => [self::RUNNING, self::CANCELLED],
            self::RUNNING => [self::COMPLETED, self::FAILED, self::CANCELLED],
            self::COMPLETED => [],
            self::FAILED => [self::PENDING], // Allow retry
            self::CANCELLED => [],
        };
    }

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

    /**
     * Check if pipeline is currently processing.
     */
    public function isActive(): bool
    {
        return $this === self::RUNNING;
    }

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

    /**
     * Get human-readable label.
     */
    public function label(): string
    {
        return match ($this) {
            self::PENDING => 'Wartend',
            self::RUNNING => 'Läuft',
            self::COMPLETED => 'Abgeschlossen',
            self::FAILED => 'Fehlgeschlagen',
            self::CANCELLED => 'Abgebrochen',
        };
    }

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