@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | public function getRenderer(?string $format = null): ?ExceptionRendererInterface |
| 49 | 49 | { |
| 50 | - if ($format !== null) { |
|
| 51 | - foreach ($this->renderers as $renderer) { |
|
| 52 | - if ($renderer->canRender($format)) { |
|
| 50 | + if ($format !== null){ |
|
| 51 | + foreach ($this->renderers as $renderer){ |
|
| 52 | + if ($renderer->canRender($format)){ |
|
| 53 | 53 | return $renderer; |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -72,18 +72,18 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | public function report(\Throwable $exception): void |
| 74 | 74 | { |
| 75 | - if ($this->shouldNotReport($exception)) { |
|
| 75 | + if ($this->shouldNotReport($exception)){ |
|
| 76 | 76 | return; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - foreach ($this->reporters as $reporter) { |
|
| 80 | - try { |
|
| 81 | - if ($reporter instanceof ExceptionReporterInterface) { |
|
| 79 | + foreach ($this->reporters as $reporter){ |
|
| 80 | + try{ |
|
| 81 | + if ($reporter instanceof ExceptionReporterInterface){ |
|
| 82 | 82 | $reporter->report($exception); |
| 83 | - } else { |
|
| 83 | + }else{ |
|
| 84 | 84 | $reporter($exception); |
| 85 | 85 | } |
| 86 | - } catch (\Throwable) { |
|
| 86 | + }catch (\Throwable){ |
|
| 87 | 87 | // Do nothing |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -91,10 +91,10 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | public function handleGlobalException(\Throwable $e): void |
| 93 | 93 | { |
| 94 | - if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) { |
|
| 94 | + if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)){ |
|
| 95 | 95 | $this->output ??= \defined('STDERR') ? \STDERR : \fopen('php://stderr', 'wb+'); |
| 96 | 96 | $format = 'cli'; |
| 97 | - } else { |
|
| 97 | + }else{ |
|
| 98 | 98 | $this->output ??= \defined('STDOUT') ? \STDOUT : \fopen('php://stdout', 'wb+'); |
| 99 | 99 | $format = 'html'; |
| 100 | 100 | } |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | $this->report($e); |
| 104 | 104 | |
| 105 | 105 | // There is possible an exception on the application termination |
| 106 | - try { |
|
| 106 | + try{ |
|
| 107 | 107 | \fwrite($this->output, $this->render($e, verbosity: $this->verbosity, format: $format)); |
| 108 | - } catch (\Throwable) { |
|
| 108 | + }catch (\Throwable){ |
|
| 109 | 109 | $this->output = null; |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | /** |
| 130 | 130 | * @param ExceptionReporterInterface|Closure(\Throwable):void $reporter |
| 131 | 131 | */ |
| 132 | - public function addReporter(ExceptionReporterInterface|Closure $reporter): void |
|
| 132 | + public function addReporter(ExceptionReporterInterface | Closure $reporter): void |
|
| 133 | 133 | { |
| 134 | 134 | $this->reporters[] = $reporter; |
| 135 | 135 | } |
@@ -147,13 +147,13 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | protected function handleShutdown(): void |
| 149 | 149 | { |
| 150 | - if (empty($error = \error_get_last())) { |
|
| 150 | + if (empty($error = \error_get_last())){ |
|
| 151 | 151 | return; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - try { |
|
| 154 | + try{ |
|
| 155 | 155 | $this->handleError($error['type'], $error['message'], $error['file'], $error['line']); |
| 156 | - } catch (\Throwable $e) { |
|
| 156 | + }catch (\Throwable $e){ |
|
| 157 | 157 | $this->handleGlobalException($e); |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | string $errfile = '', |
| 170 | 170 | int $errline = 0, |
| 171 | 171 | ): bool { |
| 172 | - if (!(\error_reporting() & $errno)) { |
|
| 172 | + if (!(\error_reporting() & $errno)){ |
|
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -183,8 +183,8 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | protected function shouldNotReport(\Throwable $exception): bool |
| 185 | 185 | { |
| 186 | - foreach ($this->nonReportableExceptions as $nonReportableException) { |
|
| 187 | - if ($exception instanceof $nonReportableException) { |
|
| 186 | + foreach ($this->nonReportableExceptions as $nonReportableException){ |
|
| 187 | + if ($exception instanceof $nonReportableException){ |
|
| 188 | 188 | return true; |
| 189 | 189 | } |
| 190 | 190 | } |
@@ -47,9 +47,12 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | public function getRenderer(?string $format = null): ?ExceptionRendererInterface |
| 49 | 49 | { |
| 50 | - if ($format !== null) { |
|
| 51 | - foreach ($this->renderers as $renderer) { |
|
| 52 | - if ($renderer->canRender($format)) { |
|
| 50 | + if ($format !== null) |
|
| 51 | + { |
|
| 52 | + foreach ($this->renderers as $renderer) |
|
| 53 | + { |
|
| 54 | + if ($renderer->canRender($format)) |
|
| 55 | + { |
|
| 53 | 56 | return $renderer; |
| 54 | 57 | } |
| 55 | 58 | } |
@@ -72,18 +75,26 @@ discard block |
||
| 72 | 75 | |
| 73 | 76 | public function report(\Throwable $exception): void |
| 74 | 77 | { |
| 75 | - if ($this->shouldNotReport($exception)) { |
|
| 78 | + if ($this->shouldNotReport($exception)) |
|
| 79 | + { |
|
| 76 | 80 | return; |
| 77 | 81 | } |
| 78 | 82 | |
| 79 | - foreach ($this->reporters as $reporter) { |
|
| 80 | - try { |
|
| 81 | - if ($reporter instanceof ExceptionReporterInterface) { |
|
| 83 | + foreach ($this->reporters as $reporter) |
|
| 84 | + { |
|
| 85 | + try |
|
| 86 | + { |
|
| 87 | + if ($reporter instanceof ExceptionReporterInterface) |
|
| 88 | + { |
|
| 82 | 89 | $reporter->report($exception); |
| 83 | - } else { |
|
| 90 | + } |
|
| 91 | + else |
|
| 92 | + { |
|
| 84 | 93 | $reporter($exception); |
| 85 | 94 | } |
| 86 | - } catch (\Throwable) { |
|
| 95 | + } |
|
| 96 | + catch (\Throwable) |
|
| 97 | + { |
|
| 87 | 98 | // Do nothing |
| 88 | 99 | } |
| 89 | 100 | } |
@@ -91,10 +102,13 @@ discard block |
||
| 91 | 102 | |
| 92 | 103 | public function handleGlobalException(\Throwable $e): void |
| 93 | 104 | { |
| 94 | - if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) { |
|
| 105 | + if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) |
|
| 106 | + { |
|
| 95 | 107 | $this->output ??= \defined('STDERR') ? \STDERR : \fopen('php://stderr', 'wb+'); |
| 96 | 108 | $format = 'cli'; |
| 97 | - } else { |
|
| 109 | + } |
|
| 110 | + else |
|
| 111 | + { |
|
| 98 | 112 | $this->output ??= \defined('STDOUT') ? \STDOUT : \fopen('php://stdout', 'wb+'); |
| 99 | 113 | $format = 'html'; |
| 100 | 114 | } |
@@ -103,9 +117,12 @@ discard block |
||
| 103 | 117 | $this->report($e); |
| 104 | 118 | |
| 105 | 119 | // There is possible an exception on the application termination |
| 106 | - try { |
|
| 120 | + try |
|
| 121 | + { |
|
| 107 | 122 | \fwrite($this->output, $this->render($e, verbosity: $this->verbosity, format: $format)); |
| 108 | - } catch (\Throwable) { |
|
| 123 | + } |
|
| 124 | + catch (\Throwable) |
|
| 125 | + { |
|
| 109 | 126 | $this->output = null; |
| 110 | 127 | } |
| 111 | 128 | } |
@@ -147,13 +164,17 @@ discard block |
||
| 147 | 164 | */ |
| 148 | 165 | protected function handleShutdown(): void |
| 149 | 166 | { |
| 150 | - if (empty($error = \error_get_last())) { |
|
| 167 | + if (empty($error = \error_get_last())) |
|
| 168 | + { |
|
| 151 | 169 | return; |
| 152 | 170 | } |
| 153 | 171 | |
| 154 | - try { |
|
| 172 | + try |
|
| 173 | + { |
|
| 155 | 174 | $this->handleError($error['type'], $error['message'], $error['file'], $error['line']); |
| 156 | - } catch (\Throwable $e) { |
|
| 175 | + } |
|
| 176 | + catch (\Throwable $e) |
|
| 177 | + { |
|
| 157 | 178 | $this->handleGlobalException($e); |
| 158 | 179 | } |
| 159 | 180 | } |
@@ -169,7 +190,8 @@ discard block |
||
| 169 | 190 | string $errfile = '', |
| 170 | 191 | int $errline = 0, |
| 171 | 192 | ): bool { |
| 172 | - if (!(\error_reporting() & $errno)) { |
|
| 193 | + if (!(\error_reporting() & $errno)) |
|
| 194 | + { |
|
| 173 | 195 | return false; |
| 174 | 196 | } |
| 175 | 197 | |
@@ -183,8 +205,10 @@ discard block |
||
| 183 | 205 | |
| 184 | 206 | protected function shouldNotReport(\Throwable $exception): bool |
| 185 | 207 | { |
| 186 | - foreach ($this->nonReportableExceptions as $nonReportableException) { |
|
| 187 | - if ($exception instanceof $nonReportableException) { |
|
| 208 | + foreach ($this->nonReportableExceptions as $nonReportableException) |
|
| 209 | + { |
|
| 210 | + if ($exception instanceof $nonReportableException) |
|
| 211 | + { |
|
| 188 | 212 | return true; |
| 189 | 213 | } |
| 190 | 214 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | private function makeEmptyErrorHandler(): ExceptionHandler |
| 135 | 135 | { |
| 136 | - return new class extends ExceptionHandler { |
|
| 136 | + return new class extends ExceptionHandler{ |
|
| 137 | 137 | protected function bootBasicHandlers(): void |
| 138 | 138 | { |
| 139 | 139 | } |
@@ -147,17 +147,17 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | public static function nonReportableExceptionsDataProvider(): \Traversable |
| 149 | 149 | { |
| 150 | - yield [new class extends ClientException {}]; |
|
| 150 | + yield [new class extends ClientException{}]; |
|
| 151 | 151 | yield [new NotFoundException()]; |
| 152 | - yield [new class extends NotFoundException {}]; |
|
| 152 | + yield [new class extends NotFoundException{}]; |
|
| 153 | 153 | yield [new ForbiddenException()]; |
| 154 | - yield [new class extends ForbiddenException {}]; |
|
| 154 | + yield [new class extends ForbiddenException{}]; |
|
| 155 | 155 | yield [new UnauthorizedException()]; |
| 156 | - yield [new class extends UnauthorizedException {}]; |
|
| 156 | + yield [new class extends UnauthorizedException{}]; |
|
| 157 | 157 | yield [new AuthorizationException()]; |
| 158 | - yield [new class extends AuthorizationException {}]; |
|
| 158 | + yield [new class extends AuthorizationException{}]; |
|
| 159 | 159 | yield [new ValidationException([])]; |
| 160 | - yield [new class([]) extends ValidationException {}]; |
|
| 160 | + yield [new class([]) extends ValidationException{}]; |
|
| 161 | 161 | yield [new TestException()]; |
| 162 | 162 | } |
| 163 | 163 | } |
@@ -133,7 +133,8 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | private function makeEmptyErrorHandler(): ExceptionHandler |
| 135 | 135 | { |
| 136 | - return new class extends ExceptionHandler { |
|
| 136 | + return new class extends ExceptionHandler |
|
| 137 | + { |
|
| 137 | 138 | protected function bootBasicHandlers(): void |
| 138 | 139 | { |
| 139 | 140 | } |
@@ -147,17 +148,29 @@ discard block |
||
| 147 | 148 | |
| 148 | 149 | public static function nonReportableExceptionsDataProvider(): \Traversable |
| 149 | 150 | { |
| 150 | - yield [new class extends ClientException {}]; |
|
| 151 | + yield [new class extends ClientException |
|
| 152 | + { |
|
| 153 | +}]; |
|
| 151 | 154 | yield [new NotFoundException()]; |
| 152 | - yield [new class extends NotFoundException {}]; |
|
| 155 | + yield [new class extends NotFoundException |
|
| 156 | + { |
|
| 157 | +}]; |
|
| 153 | 158 | yield [new ForbiddenException()]; |
| 154 | - yield [new class extends ForbiddenException {}]; |
|
| 159 | + yield [new class extends ForbiddenException |
|
| 160 | + { |
|
| 161 | +}]; |
|
| 155 | 162 | yield [new UnauthorizedException()]; |
| 156 | - yield [new class extends UnauthorizedException {}]; |
|
| 163 | + yield [new class extends UnauthorizedException |
|
| 164 | + { |
|
| 165 | +}]; |
|
| 157 | 166 | yield [new AuthorizationException()]; |
| 158 | - yield [new class extends AuthorizationException {}]; |
|
| 167 | + yield [new class extends AuthorizationException |
|
| 168 | + { |
|
| 169 | +}]; |
|
| 159 | 170 | yield [new ValidationException([])]; |
| 160 | - yield [new class([]) extends ValidationException {}]; |
|
| 171 | + yield [new class([]) extends ValidationException |
|
| 172 | + { |
|
| 173 | +}]; |
|
| 161 | 174 | yield [new TestException()]; |
| 162 | 175 | } |
| 163 | 176 | } |