@@ -5,11 +5,11 @@ |
||
| 5 | 5 | use Rector\Config\RectorConfig; |
| 6 | 6 | |
| 7 | 7 | return RectorConfig::configure() |
| 8 | - ->withPaths([ |
|
| 9 | - __DIR__ . '/src', |
|
| 10 | - __DIR__ . '/tests', |
|
| 11 | - ]) |
|
| 8 | + ->withPaths([ |
|
| 9 | + __DIR__ . '/src', |
|
| 10 | + __DIR__ . '/tests', |
|
| 11 | + ]) |
|
| 12 | 12 | ->withPhpSets() |
| 13 | - ->withTypeCoverageLevel(0) |
|
| 14 | - ->withDeadCodeLevel(0) |
|
| 15 | - ->withCodeQualityLevel(0); |
|
| 13 | + ->withTypeCoverageLevel(0) |
|
| 14 | + ->withDeadCodeLevel(0) |
|
| 15 | + ->withCodeQualityLevel(0); |
|
@@ -6,8 +6,8 @@ |
||
| 6 | 6 | |
| 7 | 7 | return RectorConfig::configure() |
| 8 | 8 | ->withPaths([ |
| 9 | - __DIR__ . '/src', |
|
| 10 | - __DIR__ . '/tests', |
|
| 9 | + __DIR__.'/src', |
|
| 10 | + __DIR__.'/tests', |
|
| 11 | 11 | ]) |
| 12 | 12 | ->withPhpSets() |
| 13 | 13 | ->withTypeCoverageLevel(0) |
@@ -9,8 +9,8 @@ discard block |
||
| 9 | 9 | * @param Throwable $e |
| 10 | 10 | * @param string $messageIntro |
| 11 | 11 | */ |
| 12 | - public static function printException(Throwable $e, $messageIntro = ''): void { |
|
| 13 | - self::p("%s[%s] %s\n", $messageIntro, get_class($e), $e->getMessage()); |
|
| 12 | + public static function printException(Throwable $e, $messageIntro = ''): void { |
|
| 13 | + self::p("%s[%s] %s\n", $messageIntro, get_class($e), $e->getMessage()); |
|
| 14 | 14 | |
| 15 | 15 | foreach($e->getTrace() as $idx => $station) { |
| 16 | 16 | self::formatStation($idx, $station); |
@@ -26,55 +26,55 @@ discard block |
||
| 26 | 26 | * @param int $idx |
| 27 | 27 | * @param array $station |
| 28 | 28 | */ |
| 29 | - /** |
|
| 30 | - * @param int $idx |
|
| 31 | - * @param array<string, mixed> $station |
|
| 32 | - */ |
|
| 33 | - private static function formatStation($idx, $station): void { |
|
| 34 | - $defaults = [ |
|
| 35 | - 'file' => null, |
|
| 36 | - 'line' => null, |
|
| 37 | - 'class' => null, |
|
| 38 | - 'function' => null, |
|
| 39 | - 'type' => null, |
|
| 40 | - 'args' => [], |
|
| 41 | - ]; |
|
| 42 | - $station = array_merge($defaults, $station); |
|
| 43 | - self::p("#%- 3s%s:%d\n", $idx, $station['file'] ?: 'unknown', $station['line']); |
|
| 44 | - if($station['class'] !== null || $station['function'] !== null) { |
|
| 45 | - $params = []; |
|
| 46 | - $args = $station['args']; |
|
| 47 | - if (!is_array($args)) { |
|
| 48 | - $args = []; |
|
| 49 | - } |
|
| 50 | - foreach($args as $argument) { |
|
| 51 | - if(is_array($argument)) { |
|
| 52 | - $params[] = sprintf('array%d', count($argument)); |
|
| 53 | - } elseif(is_object($argument)) { |
|
| 54 | - $params[] = sprintf('%s', get_class($argument)); |
|
| 55 | - } else { |
|
| 56 | - $params[] = gettype($argument); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - $func = $station['function']; |
|
| 60 | - if(is_string($func) && strpos($func, '{closure}') !== false && $station['class'] !== null) { |
|
| 61 | - $station['function'] = '{closure}'; |
|
| 62 | - } |
|
| 63 | - self::p(" %s%s%s%s%s%s\n", $station['class'], $station['type'], $station['function'], "(", join(', ', $params), ")"); |
|
| 64 | - } |
|
| 65 | - } |
|
| 29 | + /** |
|
| 30 | + * @param int $idx |
|
| 31 | + * @param array<string, mixed> $station |
|
| 32 | + */ |
|
| 33 | + private static function formatStation($idx, $station): void { |
|
| 34 | + $defaults = [ |
|
| 35 | + 'file' => null, |
|
| 36 | + 'line' => null, |
|
| 37 | + 'class' => null, |
|
| 38 | + 'function' => null, |
|
| 39 | + 'type' => null, |
|
| 40 | + 'args' => [], |
|
| 41 | + ]; |
|
| 42 | + $station = array_merge($defaults, $station); |
|
| 43 | + self::p("#%- 3s%s:%d\n", $idx, $station['file'] ?: 'unknown', $station['line']); |
|
| 44 | + if($station['class'] !== null || $station['function'] !== null) { |
|
| 45 | + $params = []; |
|
| 46 | + $args = $station['args']; |
|
| 47 | + if (!is_array($args)) { |
|
| 48 | + $args = []; |
|
| 49 | + } |
|
| 50 | + foreach($args as $argument) { |
|
| 51 | + if(is_array($argument)) { |
|
| 52 | + $params[] = sprintf('array%d', count($argument)); |
|
| 53 | + } elseif(is_object($argument)) { |
|
| 54 | + $params[] = sprintf('%s', get_class($argument)); |
|
| 55 | + } else { |
|
| 56 | + $params[] = gettype($argument); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + $func = $station['function']; |
|
| 60 | + if(is_string($func) && strpos($func, '{closure}') !== false && $station['class'] !== null) { |
|
| 61 | + $station['function'] = '{closure}'; |
|
| 62 | + } |
|
| 63 | + self::p(" %s%s%s%s%s%s\n", $station['class'], $station['type'], $station['function'], "(", join(', ', $params), ")"); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * @param string $format |
| 69 | 69 | */ |
| 70 | - private static function p($format = "\n"): void { |
|
| 71 | - $fp = fopen('php://stderr', 'w'); |
|
| 72 | - if ($fp !== false) { |
|
| 73 | - $args = array_slice(func_get_args(), 1); |
|
| 74 | - /** @var array<bool|float|int|string|null> $args */ |
|
| 75 | - $args = $args; |
|
| 76 | - fwrite($fp, vsprintf($format, $args)); |
|
| 77 | - fclose($fp); |
|
| 78 | - } |
|
| 79 | - } |
|
| 70 | + private static function p($format = "\n"): void { |
|
| 71 | + $fp = fopen('php://stderr', 'w'); |
|
| 72 | + if ($fp !== false) { |
|
| 73 | + $args = array_slice(func_get_args(), 1); |
|
| 74 | + /** @var array<bool|float|int|string|null> $args */ |
|
| 75 | + $args = $args; |
|
| 76 | + fwrite($fp, vsprintf($format, $args)); |
|
| 77 | + fclose($fp); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -12,11 +12,11 @@ discard block |
||
| 12 | 12 | public static function printException(Throwable $e, $messageIntro = ''): void { |
| 13 | 13 | self::p("%s[%s] %s\n", $messageIntro, get_class($e), $e->getMessage()); |
| 14 | 14 | |
| 15 | - foreach($e->getTrace() as $idx => $station) { |
|
| 15 | + foreach ($e->getTrace() as $idx => $station) { |
|
| 16 | 16 | self::formatStation($idx, $station); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - if($e->getPrevious() instanceof Throwable) { |
|
| 19 | + if ($e->getPrevious() instanceof Throwable) { |
|
| 20 | 20 | self::p(); |
| 21 | 21 | self::printException($e->getPrevious(), 'Previous: '); |
| 22 | 22 | } |
@@ -41,23 +41,23 @@ discard block |
||
| 41 | 41 | ]; |
| 42 | 42 | $station = array_merge($defaults, $station); |
| 43 | 43 | self::p("#%- 3s%s:%d\n", $idx, $station['file'] ?: 'unknown', $station['line']); |
| 44 | - if($station['class'] !== null || $station['function'] !== null) { |
|
| 44 | + if ($station['class'] !== null || $station['function'] !== null) { |
|
| 45 | 45 | $params = []; |
| 46 | 46 | $args = $station['args']; |
| 47 | 47 | if (!is_array($args)) { |
| 48 | 48 | $args = []; |
| 49 | 49 | } |
| 50 | - foreach($args as $argument) { |
|
| 51 | - if(is_array($argument)) { |
|
| 50 | + foreach ($args as $argument) { |
|
| 51 | + if (is_array($argument)) { |
|
| 52 | 52 | $params[] = sprintf('array%d', count($argument)); |
| 53 | - } elseif(is_object($argument)) { |
|
| 53 | + } elseif (is_object($argument)) { |
|
| 54 | 54 | $params[] = sprintf('%s', get_class($argument)); |
| 55 | 55 | } else { |
| 56 | 56 | $params[] = gettype($argument); |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | $func = $station['function']; |
| 60 | - if(is_string($func) && strpos($func, '{closure}') !== false && $station['class'] !== null) { |
|
| 60 | + if (is_string($func) && strpos($func, '{closure}') !== false && $station['class'] !== null) { |
|
| 61 | 61 | $station['function'] = '{closure}'; |
| 62 | 62 | } |
| 63 | 63 | self::p(" %s%s%s%s%s%s\n", $station['class'], $station['type'], $station['function'], "(", join(', ', $params), ")"); |
@@ -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 | |