| @@ -68,7 +68,8 @@ discard block | ||
| 68 | 68 | #[ExpectedValues(values: [\E_USER_NOTICE, \E_USER_WARNING, \E_USER_ERROR])] | 
| 69 | 69 | int $type | 
| 70 | 70 |      ): ?Throwable { | 
| 71 | -        $handler = (new class extends ExceptionHandler { | |
| 71 | + $handler = (new class extends ExceptionHandler | |
| 72 | +        { | |
| 72 | 73 | public function handleError(int $errno, string $errstr, string $errfile = '', int $errline = 0): bool | 
| 73 | 74 |              { | 
| 74 | 75 | return parent::handleError($errno, $errstr, $errfile, $errline); | 
| @@ -78,9 +79,12 @@ discard block | ||
| 78 | 79 |              { | 
| 79 | 80 | } | 
| 80 | 81 | }); | 
| 81 | -        try { | |
| 82 | + try | |
| 83 | +        { | |
| 82 | 84 | $handler->handleError(...\array_values($this->generateErrorArray($type))); | 
| 83 | -        } catch (Throwable $e) { | |
| 85 | + } | |
| 86 | + catch (Throwable $e) | |
| 87 | +        { | |
| 84 | 88 | return $e; | 
| 85 | 89 | } | 
| 86 | 90 | return null; | 
| @@ -40,9 +40,12 @@ discard block | ||
| 40 | 40 | |
| 41 | 41 | public function getRenderer(?string $format = null): ?ExceptionRendererInterface | 
| 42 | 42 |      { | 
| 43 | -        if ($format !== null) { | |
| 44 | -            foreach ($this->renderers as $renderer) { | |
| 45 | -                if ($renderer->canRender($format)) { | |
| 43 | + if ($format !== null) | |
| 44 | +        { | |
| 45 | + foreach ($this->renderers as $renderer) | |
| 46 | +            { | |
| 47 | + if ($renderer->canRender($format)) | |
| 48 | +                { | |
| 46 | 49 | return $renderer; | 
| 47 | 50 | } | 
| 48 | 51 | } | 
| @@ -65,14 +68,21 @@ discard block | ||
| 65 | 68 | |
| 66 | 69 | public function report(\Throwable $exception): void | 
| 67 | 70 |      { | 
| 68 | -        foreach ($this->reporters as $reporter) { | |
| 69 | -            try { | |
| 70 | -                if ($reporter instanceof ExceptionReporterInterface) { | |
| 71 | + foreach ($this->reporters as $reporter) | |
| 72 | +        { | |
| 73 | + try | |
| 74 | +            { | |
| 75 | + if ($reporter instanceof ExceptionReporterInterface) | |
| 76 | +                { | |
| 71 | 77 | $reporter->report($exception); | 
| 72 | -                } else { | |
| 78 | + } | |
| 79 | + else | |
| 80 | +                { | |
| 73 | 81 | $reporter($exception); | 
| 74 | 82 | } | 
| 75 | -            } catch (\Throwable) { | |
| 83 | + } | |
| 84 | + catch (\Throwable) | |
| 85 | +            { | |
| 76 | 86 | // Do nothing | 
| 77 | 87 | } | 
| 78 | 88 | } | 
| @@ -80,10 +90,13 @@ discard block | ||
| 80 | 90 | |
| 81 | 91 | public function handleGlobalException(\Throwable $e): void | 
| 82 | 92 |      { | 
| 83 | -        if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) { | |
| 93 | + if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) | |
| 94 | +        { | |
| 84 | 95 |              $this->output ??= \defined('STDERR') ? \STDERR : \fopen('php://stderr', 'wb+'); | 
| 85 | 96 | $format = 'cli'; | 
| 86 | -        } else { | |
| 97 | + } | |
| 98 | + else | |
| 99 | +        { | |
| 87 | 100 |              $this->output ??= \defined('STDOUT') ? \STDOUT : \fopen('php://stdout', 'wb+'); | 
| 88 | 101 | $format = 'html'; | 
| 89 | 102 | } | 
| @@ -92,9 +105,12 @@ discard block | ||
| 92 | 105 | $this->report($e); | 
| 93 | 106 | |
| 94 | 107 | // There is possible an exception on the application termination | 
| 95 | -        try { | |
| 108 | + try | |
| 109 | +        { | |
| 96 | 110 | \fwrite($this->output, $this->render($e, verbosity: $this->verbosity, format: $format)); | 
| 97 | -        } catch (\Throwable) { | |
| 111 | + } | |
| 112 | + catch (\Throwable) | |
| 113 | +        { | |
| 98 | 114 | $this->output = null; | 
| 99 | 115 | } | 
| 100 | 116 | } | 
| @@ -128,13 +144,17 @@ discard block | ||
| 128 | 144 | */ | 
| 129 | 145 | protected function handleShutdown(): void | 
| 130 | 146 |      { | 
| 131 | -        if (empty($error = \error_get_last())) { | |
| 147 | + if (empty($error = \error_get_last())) | |
| 148 | +        { | |
| 132 | 149 | return; | 
| 133 | 150 | } | 
| 134 | 151 | |
| 135 | -        try { | |
| 152 | + try | |
| 153 | +        { | |
| 136 | 154 | $this->handleError($error['type'], $error['message'], $error['file'], $error['line']); | 
| 137 | -        } catch (\Throwable $e) { | |
| 155 | + } | |
| 156 | + catch (\Throwable $e) | |
| 157 | +        { | |
| 138 | 158 | $this->handleGlobalException($e); | 
| 139 | 159 | } | 
| 140 | 160 | } | 
| @@ -150,7 +170,8 @@ discard block | ||
| 150 | 170 | string $errfile = '', | 
| 151 | 171 | int $errline = 0, | 
| 152 | 172 |      ): bool { | 
| 153 | -        if (!(\error_reporting() & $errno)) { | |
| 173 | + if (!(\error_reporting() & $errno)) | |
| 174 | +        { | |
| 154 | 175 | return false; | 
| 155 | 176 | } | 
| 156 | 177 | |