TenantAtlas/app/Support/OpsUx/OperationStatusNormalizer.php
2026-01-18 14:44:16 +01:00

50 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Support\OpsUx;
/**
* Normalize OperationRun legacy storage fields into Ops-UX canonical statuses.
*/
final class OperationStatusNormalizer
{
/**
* Returns one of: queued|running|succeeded|partial|failed.
*/
public static function toUxStatus(?string $status, ?string $outcome): string
{
$status = strtolower(trim((string) $status));
$outcome = strtolower(trim((string) $outcome));
if ($status === 'queued') {
return 'queued';
}
if ($status === 'running') {
return 'running';
}
// Terminal normalization (compatibility)
if ($status === 'failed' || $outcome === 'failed') {
return 'failed';
}
if ($status === 'completed' && $outcome === 'partially_succeeded') {
return 'partial';
}
if ($status === 'completed' && $outcome === 'succeeded') {
return 'succeeded';
}
// Best-effort fallback.
return match ($outcome) {
'partially_succeeded' => 'partial',
'succeeded' => 'succeeded',
'failed' => 'failed',
default => 'failed',
};
}
}