TaskerBridges/src/ExitCodeTranslator.php
Funky Waddle da1efaba55
Some checks are pending
CI / tasker-bridges (8.2) (push) Waiting to run
CI / tasker-bridges (8.3) (push) Waiting to run
feat: complete TaskerBridges with Symfony, Laravel, and Native adapters
2026-02-22 03:57:50 -06:00

38 lines
830 B
PHP

<?php
declare(strict_types=1);
namespace Phred\TaskerBridges;
use Phred\ConsoleContracts\ExitCode;
use Throwable;
use InvalidArgumentException;
use RuntimeException;
use LogicException;
/**
* Translates exceptions and codes into Phred standardized exit codes.
*/
final class ExitCodeTranslator
{
/**
* Translates an exception to an exit code.
*
* @param Throwable $throwable
* @return int
*/
public static function translate(Throwable $throwable): int
{
if ($throwable instanceof InvalidArgumentException) {
return ExitCode::USAGE;
}
if ($throwable instanceof RuntimeException || $throwable instanceof LogicException) {
return ExitCode::SOFTWARE;
}
// Default to generic failure
return ExitCode::FAILURE;
}
}