Files
michaelschiemer/src/Framework/ExceptionHandling/ErrorHandler.php
Michael Schiemer c93d3f07a2
All checks were successful
Test Runner / test-php (push) Successful in 31s
Deploy Application / deploy (push) Successful in 1m42s
Test Runner / test-basic (push) Successful in 7s
fix(Console): add void as valid return type for command methods
The MethodSignatureAnalyzer was rejecting command methods with void return
type, causing the schedule:run command to fail validation.
2025-11-26 06:16:09 +01:00

49 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Framework\ExceptionHandling;
use App\Framework\ExceptionHandling\Strategy\StrictErrorPolicy;
use ErrorException;
final readonly class ErrorHandler implements ErrorHandlerInterface
{
public function __construct(
private ErrorHandlerStrategy $strategy = new StrictErrorPolicy(),
) {
}
/**
* @throws ErrorException
*/
public function handle(
int $severity,
string $message,
?string $file = null,
?int $line = null,
): bool {
$context = ErrorContext::create(
severity : $severity,
message : $message,
file : $file,
line : $line,
isSuppressed: $this->isSuppressed($severity)
);
$decision = $this->strategy->handle($context);
return match($decision) {
ErrorDecision::HANDLED => true,
ErrorDecision::DEFER => false,
ErrorDecision::THROW => throw new ErrorException($message, 0, $severity, $file, $line),
};
}
private function isSuppressed($severity): bool
{
return ! (error_reporting() & $severity);
}
}