TenantAtlas/app/Support/Audit/AuditOutcome.php
2026-03-11 10:35:32 +01:00

45 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Support\Audit;
enum AuditOutcome: string
{
case Success = 'success';
case Failed = 'failed';
case Partial = 'partial';
case Info = 'info';
case Blocked = 'blocked';
public static function normalize(mixed $value): self
{
$normalized = is_string($value) ? strtolower(trim($value)) : null;
return match ($normalized) {
self::Success->value, 'succeeded', 'completed', 'complete', 'ok' => self::Success,
self::Failed->value, 'failure', 'error', 'errored' => self::Failed,
self::Partial->value, 'partially_succeeded', 'partial_success', 'partial_failure' => self::Partial,
self::Blocked->value, 'skipped', 'deferred', 'cancelled', 'canceled' => self::Blocked,
self::Info->value, 'pending', 'queued', 'running' => self::Info,
default => self::Info,
};
}
public static function normalizeValue(mixed $value): string
{
return self::normalize($value)->value;
}
public function label(): string
{
return match ($this) {
self::Success => 'Success',
self::Failed => 'Failed',
self::Partial => 'Partial',
self::Info => 'Info',
self::Blocked => 'Blocked',
};
}
}