DocumentStatus.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: Document-Status-Enum für Pipeline-Verarbeitung

enum DocumentStatus: string
{
    case PENDING = 'pending';
    case PROCESSING = 'processing';
    case DONE = 'done';
    case ERROR = 'error';

    /**
     * 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::PROCESSING],
            self::PROCESSING => [self::DONE, self::ERROR],
            self::DONE => [self::PENDING],
            self::ERROR => [self::PENDING],
        };
    }

    /**
     * Check if document is currently being processed.
     */
    public function isActive(): bool
    {
        return $this === self::PROCESSING;
    }

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

    /**
     * Check if document can be reprocessed.
     */
    public function canReprocess(): bool
    {
        return in_array($this, [self::DONE, self::ERROR], true);
    }

    /**
     * Check if processing was successful.
     */
    public function isSuccess(): bool
    {
        return $this === self::DONE;
    }

    /**
     * Get human-readable label.
     */
    public function label(): string
    {
        return match ($this) {
            self::PENDING => 'Wartend',
            self::PROCESSING => 'Verarbeitung',
            self::DONE => 'Fertig',
            self::ERROR => 'Fehler',
        };
    }

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