Passed
Push — master ( 403717...658d6f )
by Anton
02:47
created
src/Http/Middleware/ErrorHandlerMiddleware.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
         RendererInterface $renderer,
58 58
         ResponseFactoryInterface $responseFactory,
59 59
         ContainerInterface $container
60
-    ) {
60
+    ){
61 61
         $this->suppressErrors = $suppressErrors;
62 62
         $this->renderer = $renderer;
63 63
         $this->responseFactory = $responseFactory;
@@ -71,22 +71,22 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function process(Request $request, Handler $handler): Response
73 73
     {
74
-        try {
74
+        try{
75 75
             return $handler->handle($request);
76
-        } catch (ClientException | RouterException $e) {
77
-            if ($e instanceof ClientException) {
76
+        }catch (ClientException | RouterException $e){
77
+            if ($e instanceof ClientException){
78 78
                 $code = $e->getCode();
79
-            } else {
79
+            }else{
80 80
                 $code = 404;
81 81
             }
82
-        } catch (\Throwable $e) {
82
+        }catch (\Throwable $e){
83 83
             $snapshotter = $this->getOptional(SnapshotterInterface::class);
84
-            if ($snapshotter !== null) {
84
+            if ($snapshotter !== null){
85 85
                 /** @var SnapshotterInterface $snapshotter */
86 86
                 $snapshotter->register($e);
87 87
             }
88 88
 
89
-            if (!$this->suppressErrors) {
89
+            if (!$this->suppressErrors){
90 90
                 return $this->renderError($request, $e);
91 91
             }
92 92
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     {
110 110
         $response = $this->responseFactory->createResponse(500);
111 111
 
112
-        if ($request->getHeaderLine('Accept') == 'application/json') {
112
+        if ($request->getHeaderLine('Accept') == 'application/json'){
113 113
             $response = $response->withHeader('Content-Type', 'application/json');
114 114
             $handler = new JsonHandler();
115 115
             $response->getBody()->write(json_encode(
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
                     true
120 120
                 )
121 121
             ));
122
-        } else {
122
+        }else{
123 123
             $handler = new HtmlHandler();
124 124
             $state = $this->getOptional(StateInterface::class);
125
-            if ($state !== null) {
125
+            if ($state !== null){
126 126
                 $handler = $handler->withState($state);
127 127
             }
128 128
 
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
      */
157 157
     private function getOptional(string $class)
158 158
     {
159
-        try {
159
+        try{
160 160
             return $this->container->get($class);
161
-        } catch (\Throwable | ContainerExceptionInterface $se) {
161
+        }catch (\Throwable | ContainerExceptionInterface $se){
162 162
             return null;
163 163
         }
164 164
     }
Please login to merge, or discard this patch.
Braces   +29 added lines, -12 removed lines patch added patch discarded remove patch
@@ -71,22 +71,32 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function process(Request $request, Handler $handler): Response
73 73
     {
74
-        try {
74
+        try
75
+        {
75 76
             return $handler->handle($request);
76
-        } catch (ClientException | RouterException $e) {
77
-            if ($e instanceof ClientException) {
77
+        }
78
+        catch (ClientException | RouterException $e)
79
+        {
80
+            if ($e instanceof ClientException)
81
+            {
78 82
                 $code = $e->getCode();
79
-            } else {
83
+            }
84
+            else
85
+            {
80 86
                 $code = 404;
81 87
             }
82
-        } catch (\Throwable $e) {
88
+        }
89
+        catch (\Throwable $e)
90
+        {
83 91
             $snapshotter = $this->getOptional(SnapshotterInterface::class);
84
-            if ($snapshotter !== null) {
92
+            if ($snapshotter !== null)
93
+            {
85 94
                 /** @var SnapshotterInterface $snapshotter */
86 95
                 $snapshotter->register($e);
87 96
             }
88 97
 
89
-            if (!$this->suppressErrors) {
98
+            if (!$this->suppressErrors)
99
+            {
90 100
                 return $this->renderError($request, $e);
91 101
             }
92 102
 
@@ -109,7 +119,8 @@  discard block
 block discarded – undo
109 119
     {
110 120
         $response = $this->responseFactory->createResponse(500);
111 121
 
112
-        if ($request->getHeaderLine('Accept') == 'application/json') {
122
+        if ($request->getHeaderLine('Accept') == 'application/json')
123
+        {
113 124
             $response = $response->withHeader('Content-Type', 'application/json');
114 125
             $handler = new JsonHandler();
115 126
             $response->getBody()->write(json_encode(
@@ -119,10 +130,13 @@  discard block
 block discarded – undo
119 130
                     true
120 131
                 )
121 132
             ));
122
-        } else {
133
+        }
134
+        else
135
+        {
123 136
             $handler = new HtmlHandler();
124 137
             $state = $this->getOptional(StateInterface::class);
125
-            if ($state !== null) {
138
+            if ($state !== null)
139
+            {
126 140
                 $handler = $handler->withState($state);
127 141
             }
128 142
 
@@ -156,9 +170,12 @@  discard block
 block discarded – undo
156 170
      */
157 171
     private function getOptional(string $class)
158 172
     {
159
-        try {
173
+        try
174
+        {
160 175
             return $this->container->get($class);
161
-        } catch (\Throwable | ContainerExceptionInterface $se) {
176
+        }
177
+        catch (\Throwable | ContainerExceptionInterface $se)
178
+        {
162 179
             return null;
163 180
         }
164 181
     }
Please login to merge, or discard this patch.
src/Http/ErrorHandler/PlainRenderer.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,9 +40,9 @@
 block discarded – undo
40 40
     public function renderException(Request $request, int $code, string $message): Response
41 41
     {
42 42
         $response = $this->responseFactory->createResponse($code);
43
-        if ($request->getHeaderLine('Accept') == 'application/json') {
43
+        if ($request->getHeaderLine('Accept') == 'application/json'){
44 44
             $response->getBody()->write(json_encode(['status' => $code, 'error' => $message]));
45
-        } else {
45
+        }else{
46 46
             $response->getBody()->write("Error code: {$code}");
47 47
         }
48 48
 
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,9 +40,12 @@
 block discarded – undo
40 40
     public function renderException(Request $request, int $code, string $message): Response
41 41
     {
42 42
         $response = $this->responseFactory->createResponse($code);
43
-        if ($request->getHeaderLine('Accept') == 'application/json') {
43
+        if ($request->getHeaderLine('Accept') == 'application/json')
44
+        {
44 45
             $response->getBody()->write(json_encode(['status' => $code, 'error' => $message]));
45
-        } else {
46
+        }
47
+        else
48
+        {
46 49
             $response->getBody()->write("Error code: {$code}");
47 50
         }
48 51
 
Please login to merge, or discard this patch.