@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | * @param int $bitmask |
| 31 | 31 | */ |
| 32 | 32 | public static function enableExceptionsForErrors(int $bitmask = E_ALL): void { |
| 33 | - set_error_handler(function ($level, $message, $file, $line) use ($bitmask) { |
|
| 34 | - if(0 === error_reporting()) { |
|
| 33 | + set_error_handler(function($level, $message, $file, $line) use ($bitmask) { |
|
| 34 | + if (0 === error_reporting()) { |
|
| 35 | 35 | return false; |
| 36 | 36 | } |
| 37 | - if(($bitmask & $level) !== 0) { |
|
| 37 | + if (($bitmask & $level) !== 0) { |
|
| 38 | 38 | throw new ErrorException($message, 0, $level, $file, $line); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param string $logLevel PSR-3 Log-Level |
| 48 | 48 | */ |
| 49 | 49 | public static function registerAssertionHandler(LoggerInterface $logger, string $logLevel): void { |
| 50 | - if(self::$assertionLogger === null) { |
|
| 50 | + if (self::$assertionLogger === null) { |
|
| 51 | 51 | self::$assertionLogger = new LoggerCollection(); |
| 52 | 52 | |
| 53 | 53 | // PHP 8.0+ throws AssertionError by default (assert.exception=1) |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | $previousHandler = set_exception_handler(null); |
| 56 | 56 | restore_exception_handler(); |
| 57 | 57 | |
| 58 | - set_exception_handler(static function (Throwable $exception) use ($previousHandler, $logLevel): void { |
|
| 59 | - if($exception instanceof \AssertionError) { |
|
| 58 | + set_exception_handler(static function(Throwable $exception) use ($previousHandler, $logLevel): void { |
|
| 59 | + if ($exception instanceof \AssertionError) { |
|
| 60 | 60 | // Log the assertion failure |
| 61 | 61 | self::$assertionLogger?->log($logLevel, $exception->getMessage(), [ |
| 62 | 62 | 'file' => $exception->getFile(), |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // Pass other exceptions to previous handler or re-throw |
| 70 | - if($previousHandler !== null) { |
|
| 70 | + if ($previousHandler !== null) { |
|
| 71 | 71 | $previousHandler($exception); |
| 72 | 72 | } else { |
| 73 | 73 | throw $exception; |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | * @param LoggerInterface $logger |
| 82 | 82 | */ |
| 83 | 83 | public static function registerFatalErrorHandler(LoggerInterface $logger): void { |
| 84 | - if(self::$fatalLogger === null) { |
|
| 84 | + if (self::$fatalLogger === null) { |
|
| 85 | 85 | self::$fatalLogger = new LoggerCollection(); |
| 86 | - register_shutdown_function(function (): void { |
|
| 86 | + register_shutdown_function(function(): void { |
|
| 87 | 87 | $error = error_get_last(); |
| 88 | - if($error !== null && in_array($error['type'], self::FATAL_LEVELS, true)) { |
|
| 88 | + if ($error !== null && in_array($error['type'], self::FATAL_LEVELS, true)) { |
|
| 89 | 89 | $fl = new LogLevelRangeFilter(self::$fatalLogger ?? new LoggerCollection(), LogLevel::ERROR); |
| 90 | 90 | $fl->log(LogLevel::ALERT, $error['message'], $error); |
| 91 | 91 | } |
@@ -95,14 +95,14 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | public static function registerExceptionHandler(LoggerInterface $logger): void { |
| 98 | - if(self::$exceptionLogger === null) { |
|
| 98 | + if (self::$exceptionLogger === null) { |
|
| 99 | 99 | self::$exceptionLogger = new LoggerCollection(); |
| 100 | - set_exception_handler(static function (Throwable $exception): void { |
|
| 100 | + set_exception_handler(static function(Throwable $exception): void { |
|
| 101 | 101 | $log = new LogLevelRangeFilter(self::$exceptionLogger ?? new LoggerCollection(), LogLevel::ERROR); |
| 102 | 102 | try { |
| 103 | 103 | $exceptionAsArray = self::getExceptionAsArray($exception, true, true); |
| 104 | 104 | $log->log(LogLevel::CRITICAL, $exception->getMessage(), ['exception' => $exceptionAsArray]); |
| 105 | - } catch(Throwable) { |
|
| 105 | + } catch (Throwable) { |
|
| 106 | 106 | $exceptionAsArray1 = self::getExceptionAsArray($exception, false, false); |
| 107 | 107 | $log->log(LogLevel::CRITICAL, $exception->getMessage(), ['exception' => $exceptionAsArray1]); |
| 108 | 108 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @phpstan-return TExceptionArray|null |
| 122 | 122 | */ |
| 123 | 123 | private static function getExceptionAsArray(?Throwable $exception, bool $previous, bool $withTrace): ?array { |
| 124 | - if($exception === null) { |
|
| 124 | + if ($exception === null) { |
|
| 125 | 125 | return null; |
| 126 | 126 | } |
| 127 | 127 | |