Passed
Pull Request — master (#1044)
by Maxim
19:32
created
src/Exceptions/tests/ExceptionHandlerTest.php 1 patch
Braces   +20 added lines, -7 removed lines patch added patch discarded remove patch
@@ -132,7 +132,8 @@  discard block
 block discarded – undo
132 132
 
133 133
     private function makeEmptyErrorHandler(): ExceptionHandler
134 134
     {
135
-        return new class extends ExceptionHandler {
135
+        return new class extends ExceptionHandler
136
+        {
136 137
             protected function bootBasicHandlers(): void
137 138
             {
138 139
             }
@@ -146,16 +147,28 @@  discard block
 block discarded – undo
146 147
 
147 148
     public static function nonReportableExceptionsDataProvider(): \Traversable
148 149
     {
149
-        yield [new class extends ClientException {}];
150
+        yield [new class extends ClientException
151
+        {
152
+}];
150 153
         yield [new NotFoundException()];
151
-        yield [new class extends NotFoundException {}];
154
+        yield [new class extends NotFoundException
155
+        {
156
+}];
152 157
         yield [new ForbiddenException()];
153
-        yield [new class extends ForbiddenException {}];
158
+        yield [new class extends ForbiddenException
159
+        {
160
+}];
154 161
         yield [new UnauthorizedException()];
155
-        yield [new class extends UnauthorizedException {}];
162
+        yield [new class extends UnauthorizedException
163
+        {
164
+}];
156 165
         yield [new AuthorizationException()];
157
-        yield [new class extends AuthorizationException {}];
166
+        yield [new class extends AuthorizationException
167
+        {
168
+}];
158 169
         yield [new ValidationException([])];
159
-        yield [new class([]) extends ValidationException {}];
170
+        yield [new class([]) extends ValidationException
171
+        {
172
+}];
160 173
     }
161 174
 }
Please login to merge, or discard this patch.
src/Exceptions/src/ExceptionHandler.php 1 patch
Braces   +43 added lines, -19 removed lines patch added patch discarded remove patch
@@ -47,9 +47,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.