Passed
Push — master ( bc79a5...b222de )
by Anton
02:01
created
src/Http/SapiRequestFactory.php 2 patches
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         StreamFactoryInterface $streamFactory,
70 70
         UploadedFileFactoryInterface $uploadedFileFactory
71 71
 
72
-    ) {
72
+    ){
73 73
         $this->requestFactory = $requestFactory;
74 74
         $this->uriFactory = $uriFactory;
75 75
         $this->streamFactory = $streamFactory;
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
         $uri = $this->getUri($server, $headers);
117 117
 
118 118
         $request = $this->requestFactory->createServerRequest($method, $uri, $server);
119
-        foreach ($headers as $name => $value) {
119
+        foreach ($headers as $name => $value){
120 120
             $request = $request->withAddedHeader($name, $value);
121 121
         }
122 122
 
123 123
         $protocol = '1.1';
124
-        if (!empty($_SERVER['SERVER_PROTOCOL'])) {
124
+        if (!empty($_SERVER['SERVER_PROTOCOL'])){
125 125
             $protocol = str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']);
126 126
         }
127 127
 
@@ -132,15 +132,15 @@  discard block
 block discarded – undo
132 132
             ->withCookieParams($cookies)
133 133
             ->withUploadedFiles($this->getUploadedFilesArray($files));
134 134
 
135
-        if ($body === null) {
135
+        if ($body === null){
136 136
             return $request;
137 137
         }
138 138
 
139
-        if (\is_resource($body)) {
139
+        if (\is_resource($body)){
140 140
             $body = $this->streamFactory->createStreamFromResource($body);
141
-        } elseif (\is_string($body)) {
141
+        } elseif (\is_string($body)){
142 142
             $body = $this->streamFactory->createStream($body);
143
-        } elseif (!$body instanceof StreamInterface) {
143
+        } elseif (!$body instanceof StreamInterface){
144 144
             throw new \InvalidArgumentException(
145 145
                 'Body parameter for ServerRequestFactory::createFromParameters() must be instance of StreamInterface, resource or null.'
146 146
             );
@@ -157,29 +157,29 @@  discard block
 block discarded – undo
157 157
     private function getUri(array $server, array $headers): UriInterface
158 158
     {
159 159
         $uri = $this->uriFactory->createUri();
160
-        if (isset($server['HTTPS'])) {
160
+        if (isset($server['HTTPS'])){
161 161
             $uri = $uri->withScheme($server['HTTPS'] === 'on' ? 'https' : 'http');
162 162
         }
163 163
 
164
-        if (isset($server['HTTP_HOST'])) {
165
-            if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) {
164
+        if (isset($server['HTTP_HOST'])){
165
+            if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)){
166 166
                 $uri = $uri->withHost($matches[1])->withPort($matches[2]);
167
-            } else {
167
+            }else{
168 168
                 $uri = $uri->withHost($server['HTTP_HOST']);
169 169
             }
170
-        } elseif (isset($server['SERVER_NAME'])) {
170
+        } elseif (isset($server['SERVER_NAME'])){
171 171
             $uri = $uri->withHost($server['SERVER_NAME']);
172 172
         }
173 173
 
174
-        if (isset($server['SERVER_PORT'])) {
174
+        if (isset($server['SERVER_PORT'])){
175 175
             $uri = $uri->withPort($server['SERVER_PORT']);
176 176
         }
177 177
 
178
-        if (isset($server['REQUEST_URI'])) {
178
+        if (isset($server['REQUEST_URI'])){
179 179
             $uri = $uri->withPath(\explode('?', $server['REQUEST_URI'])[0]);
180 180
         }
181 181
 
182
-        if (isset($server['QUERY_STRING'])) {
182
+        if (isset($server['QUERY_STRING'])){
183 183
             $uri = $uri->withQuery($server['QUERY_STRING']);
184 184
         }
185 185
 
@@ -191,12 +191,12 @@  discard block
 block discarded – undo
191 191
      */
192 192
     private static function getHeadersFromGlobals(): array
193 193
     {
194
-        if (\function_exists('getallheaders')) {
194
+        if (\function_exists('getallheaders')){
195 195
             $headers = getallheaders();
196
-        } else {
196
+        }else{
197 197
             $headers = [];
198
-            foreach ($_SERVER as $name => $value) {
199
-                if (strncmp($name, 'HTTP_', 5) === 0) {
198
+            foreach ($_SERVER as $name => $value){
199
+                if (strncmp($name, 'HTTP_', 5) === 0){
200 200
                     $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
201 201
                     $headers[$name] = $value;
202 202
                 }
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
     private function getUploadedFilesArray(array $filesArray): array
214 214
     {
215 215
         $files = [];
216
-        foreach ($filesArray as $class => $info) {
216
+        foreach ($filesArray as $class => $info){
217 217
             $files[$class] = [];
218 218
             $this->populateUploadedFileRecursive(
219 219
                 $files[$class],
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
      */
242 242
     private function populateUploadedFileRecursive(&$files, $names, $tempNames, $types, $sizes, $errors): void
243 243
     {
244
-        if (\is_array($names)) {
245
-            foreach ($names as $i => $name) {
244
+        if (\is_array($names)){
245
+            foreach ($names as $i => $name){
246 246
                 $files[$i] = [];
247 247
                 $this->populateUploadedFileRecursive(
248 248
                     $files[$i],
@@ -253,10 +253,10 @@  discard block
 block discarded – undo
253 253
                     $errors[$i]
254 254
                 );
255 255
             }
256
-        } else {
257
-            try {
256
+        }else{
257
+            try{
258 258
                 $stream = $this->streamFactory->createStreamFromFile($tempNames);
259
-            } catch (\RuntimeException $e) {
259
+            }catch (\RuntimeException $e){
260 260
                 $stream = $this->streamFactory->createStream();
261 261
             }
262 262
 
Please login to merge, or discard this patch.
Braces   +55 added lines, -24 removed lines patch added patch discarded remove patch
@@ -116,12 +116,14 @@  discard block
 block discarded – undo
116 116
         $uri = $this->getUri($server, $headers);
117 117
 
118 118
         $request = $this->requestFactory->createServerRequest($method, $uri, $server);
119
-        foreach ($headers as $name => $value) {
119
+        foreach ($headers as $name => $value)
120
+        {
120 121
             $request = $request->withAddedHeader($name, $value);
121 122
         }
122 123
 
123 124
         $protocol = '1.1';
124
-        if (!empty($_SERVER['SERVER_PROTOCOL'])) {
125
+        if (!empty($_SERVER['SERVER_PROTOCOL']))
126
+        {
125 127
             $protocol = str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']);
126 128
         }
127 129
 
@@ -132,15 +134,21 @@  discard block
 block discarded – undo
132 134
             ->withCookieParams($cookies)
133 135
             ->withUploadedFiles($this->getUploadedFilesArray($files));
134 136
 
135
-        if ($body === null) {
137
+        if ($body === null)
138
+        {
136 139
             return $request;
137 140
         }
138 141
 
139
-        if (\is_resource($body)) {
142
+        if (\is_resource($body))
143
+        {
140 144
             $body = $this->streamFactory->createStreamFromResource($body);
141
-        } elseif (\is_string($body)) {
145
+        }
146
+        elseif (\is_string($body))
147
+        {
142 148
             $body = $this->streamFactory->createStream($body);
143
-        } elseif (!$body instanceof StreamInterface) {
149
+        }
150
+        elseif (!$body instanceof StreamInterface)
151
+        {
144 152
             throw new \InvalidArgumentException(
145 153
                 'Body parameter for ServerRequestFactory::createFromParameters() must be instance of StreamInterface, resource or null.'
146 154
             );
@@ -157,29 +165,39 @@  discard block
 block discarded – undo
157 165
     private function getUri(array $server, array $headers): UriInterface
158 166
     {
159 167
         $uri = $this->uriFactory->createUri();
160
-        if (isset($server['HTTPS'])) {
168
+        if (isset($server['HTTPS']))
169
+        {
161 170
             $uri = $uri->withScheme($server['HTTPS'] === 'on' ? 'https' : 'http');
162 171
         }
163 172
 
164
-        if (isset($server['HTTP_HOST'])) {
165
-            if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) {
173
+        if (isset($server['HTTP_HOST']))
174
+        {
175
+            if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches))
176
+            {
166 177
                 $uri = $uri->withHost($matches[1])->withPort($matches[2]);
167
-            } else {
178
+            }
179
+            else
180
+            {
168 181
                 $uri = $uri->withHost($server['HTTP_HOST']);
169 182
             }
170
-        } elseif (isset($server['SERVER_NAME'])) {
183
+        }
184
+        elseif (isset($server['SERVER_NAME']))
185
+        {
171 186
             $uri = $uri->withHost($server['SERVER_NAME']);
172 187
         }
173 188
 
174
-        if (isset($server['SERVER_PORT'])) {
189
+        if (isset($server['SERVER_PORT']))
190
+        {
175 191
             $uri = $uri->withPort($server['SERVER_PORT']);
176 192
         }
177 193
 
178
-        if (isset($server['REQUEST_URI'])) {
194
+        if (isset($server['REQUEST_URI']))
195
+        {
179 196
             $uri = $uri->withPath(\explode('?', $server['REQUEST_URI'])[0]);
180 197
         }
181 198
 
182
-        if (isset($server['QUERY_STRING'])) {
199
+        if (isset($server['QUERY_STRING']))
200
+        {
183 201
             $uri = $uri->withQuery($server['QUERY_STRING']);
184 202
         }
185 203
 
@@ -191,12 +209,17 @@  discard block
 block discarded – undo
191 209
      */
192 210
     private static function getHeadersFromGlobals(): array
193 211
     {
194
-        if (\function_exists('getallheaders')) {
212
+        if (\function_exists('getallheaders'))
213
+        {
195 214
             $headers = getallheaders();
196
-        } else {
215
+        }
216
+        else
217
+        {
197 218
             $headers = [];
198
-            foreach ($_SERVER as $name => $value) {
199
-                if (strncmp($name, 'HTTP_', 5) === 0) {
219
+            foreach ($_SERVER as $name => $value)
220
+            {
221
+                if (strncmp($name, 'HTTP_', 5) === 0)
222
+                {
200 223
                     $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
201 224
                     $headers[$name] = $value;
202 225
                 }
@@ -213,7 +236,8 @@  discard block
 block discarded – undo
213 236
     private function getUploadedFilesArray(array $filesArray): array
214 237
     {
215 238
         $files = [];
216
-        foreach ($filesArray as $class => $info) {
239
+        foreach ($filesArray as $class => $info)
240
+        {
217 241
             $files[$class] = [];
218 242
             $this->populateUploadedFileRecursive(
219 243
                 $files[$class],
@@ -241,8 +265,10 @@  discard block
 block discarded – undo
241 265
      */
242 266
     private function populateUploadedFileRecursive(&$files, $names, $tempNames, $types, $sizes, $errors): void
243 267
     {
244
-        if (\is_array($names)) {
245
-            foreach ($names as $i => $name) {
268
+        if (\is_array($names))
269
+        {
270
+            foreach ($names as $i => $name)
271
+            {
246 272
                 $files[$i] = [];
247 273
                 $this->populateUploadedFileRecursive(
248 274
                     $files[$i],
@@ -253,10 +279,15 @@  discard block
 block discarded – undo
253 279
                     $errors[$i]
254 280
                 );
255 281
             }
256
-        } else {
257
-            try {
282
+        }
283
+        else
284
+        {
285
+            try
286
+            {
258 287
                 $stream = $this->streamFactory->createStreamFromFile($tempNames);
259
-            } catch (\RuntimeException $e) {
288
+            }
289
+            catch (\RuntimeException $e)
290
+            {
260 291
                 $stream = $this->streamFactory->createStream();
261 292
             }
262 293
 
Please login to merge, or discard this patch.