← Code-Übersicht

InvoiceErrorCode.php

Pfad: src/Domain/Rechnung/InvoiceErrorCode.php

Ext: php

Größe: 1808 Bytes

Geändert: 2026-07-16 14:10:16+02

<?php
declare(strict_types=1);

namespace Demo\Domain\Rechnung;

/**
 * Normierte Fehlercodes fuer kontrollierte Fehlerbehandlung.
 */
final class InvoiceErrorCode
{
    public const AUTH = 'AUTH';
    public const DOWNLOAD = 'DOWNLOAD';
    public const EXTRACT = 'EXTRACT';
    public const VENDOR_MATCH = 'VENDOR_MATCH';
    public const POSTING = 'POSTING';
    public const PERSISTENCE = 'PERSISTENCE';

    /**
     * @param string $code Fehlercode.
     * @return bool True, falls automatisch erneut versucht werden soll.
     */
    public static function isRetryable(string $code): bool
    {
        return in_array($code, [self::AUTH, self::DOWNLOAD, self::POSTING], true);
    }

    /**
     * @param string $code Fehlercode.
     * @return string Passender Laufstatus.
     */
    public static function statusForError(string $code): string
    {
        return match ($code) {
            self::AUTH => InvoiceStatus::ERROR_AUTH,
            self::DOWNLOAD => InvoiceStatus::ERROR_DOWNLOAD,
            self::EXTRACT => InvoiceStatus::ERROR_EXTRACT,
            self::VENDOR_MATCH => InvoiceStatus::ERROR_VENDOR_MATCH,
            self::PERSISTENCE, self::POSTING => InvoiceStatus::ERROR_POSTING,
            default => InvoiceStatus::ERROR_EXTRACT,
        };
    }

    /**
     * @param string $code Fehlercode.
     * @return string Schrittbezeichnung fuer Logging.
     */
    public static function stepForCode(string $code): string
    {
        return match ($code) {
            self::AUTH => 'Anmeldung',
            self::DOWNLOAD => 'Download',
            self::EXTRACT => 'Extraktion',
            self::VENDOR_MATCH => 'Kontaktabgleich',
            self::POSTING => 'Buchung',
            self::PERSISTENCE => 'Persistenz',
            default => 'Unknown',
        };
    }
}