@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | UriFactoryInterface $uriFactory, |
78 | 78 | StreamFactoryInterface $streamFactory, |
79 | 79 | UploadedFileFactoryInterface $uploadedFileFactory |
80 | - ) { |
|
80 | + ){ |
|
81 | 81 | $this->requestFactory = $requestFactory; |
82 | 82 | $this->uriFactory = $uriFactory; |
83 | 83 | $this->streamFactory = $streamFactory; |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | $uri = $this->getUri($server, $headers); |
125 | 125 | |
126 | 126 | $request = $this->requestFactory->createServerRequest($method, $uri, $server); |
127 | - foreach ($headers as $name => $value) { |
|
127 | + foreach ($headers as $name => $value){ |
|
128 | 128 | $request = $request->withAddedHeader($name, $value); |
129 | 129 | } |
130 | 130 | |
131 | 131 | $protocol = '1.1'; |
132 | - if (!empty($_SERVER['SERVER_PROTOCOL'])) { |
|
132 | + if (!empty($_SERVER['SERVER_PROTOCOL'])){ |
|
133 | 133 | $protocol = str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']); |
134 | 134 | } |
135 | 135 | |
@@ -140,15 +140,15 @@ discard block |
||
140 | 140 | ->withCookieParams($cookies) |
141 | 141 | ->withUploadedFiles($this->getUploadedFilesArray($files)); |
142 | 142 | |
143 | - if ($body === null) { |
|
143 | + if ($body === null){ |
|
144 | 144 | return $request; |
145 | 145 | } |
146 | 146 | |
147 | - if (\is_resource($body)) { |
|
147 | + if (\is_resource($body)){ |
|
148 | 148 | $body = $this->streamFactory->createStreamFromResource($body); |
149 | - } elseif (\is_string($body)) { |
|
149 | + } elseif (\is_string($body)){ |
|
150 | 150 | $body = $this->streamFactory->createStream($body); |
151 | - } elseif (!$body instanceof StreamInterface) { |
|
151 | + } elseif (!$body instanceof StreamInterface){ |
|
152 | 152 | throw new \InvalidArgumentException( |
153 | 153 | 'Body parameter for ServerRequestFactory::createFromParameters() ' |
154 | 154 | . 'must be instance of StreamInterface, resource or null.' |
@@ -166,29 +166,29 @@ discard block |
||
166 | 166 | private function getUri(array $server, array $headers): UriInterface |
167 | 167 | { |
168 | 168 | $uri = $this->uriFactory->createUri(); |
169 | - if (isset($server['HTTPS'])) { |
|
169 | + if (isset($server['HTTPS'])){ |
|
170 | 170 | $uri = $uri->withScheme($server['HTTPS'] === 'on' ? 'https' : 'http'); |
171 | 171 | } |
172 | 172 | |
173 | - if (isset($server['HTTP_HOST'])) { |
|
174 | - if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) { |
|
173 | + if (isset($server['HTTP_HOST'])){ |
|
174 | + if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)){ |
|
175 | 175 | $uri = $uri->withHost($matches[1])->withPort($matches[2]); |
176 | - } else { |
|
176 | + }else{ |
|
177 | 177 | $uri = $uri->withHost($server['HTTP_HOST']); |
178 | 178 | } |
179 | - } elseif (isset($server['SERVER_NAME'])) { |
|
179 | + } elseif (isset($server['SERVER_NAME'])){ |
|
180 | 180 | $uri = $uri->withHost($server['SERVER_NAME']); |
181 | 181 | } |
182 | 182 | |
183 | - if (isset($server['SERVER_PORT'])) { |
|
183 | + if (isset($server['SERVER_PORT'])){ |
|
184 | 184 | $uri = $uri->withPort($server['SERVER_PORT']); |
185 | 185 | } |
186 | 186 | |
187 | - if (isset($server['REQUEST_URI'])) { |
|
187 | + if (isset($server['REQUEST_URI'])){ |
|
188 | 188 | $uri = $uri->withPath(\explode('?', $server['REQUEST_URI'])[0]); |
189 | 189 | } |
190 | 190 | |
191 | - if (isset($server['QUERY_STRING'])) { |
|
191 | + if (isset($server['QUERY_STRING'])){ |
|
192 | 192 | $uri = $uri->withQuery($server['QUERY_STRING']); |
193 | 193 | } |
194 | 194 | |
@@ -200,12 +200,12 @@ discard block |
||
200 | 200 | */ |
201 | 201 | private static function getHeadersFromGlobals(): array |
202 | 202 | { |
203 | - if (\function_exists('getallheaders')) { |
|
203 | + if (\function_exists('getallheaders')){ |
|
204 | 204 | $headers = getallheaders(); |
205 | - } else { |
|
205 | + }else{ |
|
206 | 206 | $headers = []; |
207 | - foreach ($_SERVER as $name => $value) { |
|
208 | - if (strncmp($name, 'HTTP_', 5) === 0) { |
|
207 | + foreach ($_SERVER as $name => $value){ |
|
208 | + if (strncmp($name, 'HTTP_', 5) === 0){ |
|
209 | 209 | $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); |
210 | 210 | $headers[$name] = $value; |
211 | 211 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | private function getUploadedFilesArray(array $filesArray): array |
223 | 223 | { |
224 | 224 | $files = []; |
225 | - foreach ($filesArray as $class => $info) { |
|
225 | + foreach ($filesArray as $class => $info){ |
|
226 | 226 | $files[$class] = []; |
227 | 227 | $this->populateUploadedFileRecursive( |
228 | 228 | $files[$class], |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | */ |
251 | 251 | private function populateUploadedFileRecursive(&$files, $names, $tempNames, $types, $sizes, $errors): void |
252 | 252 | { |
253 | - if (\is_array($names)) { |
|
254 | - foreach ($names as $i => $name) { |
|
253 | + if (\is_array($names)){ |
|
254 | + foreach ($names as $i => $name){ |
|
255 | 255 | $files[$i] = []; |
256 | 256 | $this->populateUploadedFileRecursive( |
257 | 257 | $files[$i], |
@@ -262,10 +262,10 @@ discard block |
||
262 | 262 | $errors[$i] |
263 | 263 | ); |
264 | 264 | } |
265 | - } else { |
|
266 | - try { |
|
265 | + }else{ |
|
266 | + try{ |
|
267 | 267 | $stream = $this->streamFactory->createStreamFromFile($tempNames); |
268 | - } catch (\RuntimeException $e) { |
|
268 | + }catch (\RuntimeException $e){ |
|
269 | 269 | $stream = $this->streamFactory->createStream(); |
270 | 270 | } |
271 | 271 |
@@ -124,12 +124,14 @@ discard block |
||
124 | 124 | $uri = $this->getUri($server, $headers); |
125 | 125 | |
126 | 126 | $request = $this->requestFactory->createServerRequest($method, $uri, $server); |
127 | - foreach ($headers as $name => $value) { |
|
127 | + foreach ($headers as $name => $value) |
|
128 | + { |
|
128 | 129 | $request = $request->withAddedHeader($name, $value); |
129 | 130 | } |
130 | 131 | |
131 | 132 | $protocol = '1.1'; |
132 | - if (!empty($_SERVER['SERVER_PROTOCOL'])) { |
|
133 | + if (!empty($_SERVER['SERVER_PROTOCOL'])) |
|
134 | + { |
|
133 | 135 | $protocol = str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']); |
134 | 136 | } |
135 | 137 | |
@@ -140,15 +142,21 @@ discard block |
||
140 | 142 | ->withCookieParams($cookies) |
141 | 143 | ->withUploadedFiles($this->getUploadedFilesArray($files)); |
142 | 144 | |
143 | - if ($body === null) { |
|
145 | + if ($body === null) |
|
146 | + { |
|
144 | 147 | return $request; |
145 | 148 | } |
146 | 149 | |
147 | - if (\is_resource($body)) { |
|
150 | + if (\is_resource($body)) |
|
151 | + { |
|
148 | 152 | $body = $this->streamFactory->createStreamFromResource($body); |
149 | - } elseif (\is_string($body)) { |
|
153 | + } |
|
154 | + elseif (\is_string($body)) |
|
155 | + { |
|
150 | 156 | $body = $this->streamFactory->createStream($body); |
151 | - } elseif (!$body instanceof StreamInterface) { |
|
157 | + } |
|
158 | + elseif (!$body instanceof StreamInterface) |
|
159 | + { |
|
152 | 160 | throw new \InvalidArgumentException( |
153 | 161 | 'Body parameter for ServerRequestFactory::createFromParameters() ' |
154 | 162 | . 'must be instance of StreamInterface, resource or null.' |
@@ -166,29 +174,39 @@ discard block |
||
166 | 174 | private function getUri(array $server, array $headers): UriInterface |
167 | 175 | { |
168 | 176 | $uri = $this->uriFactory->createUri(); |
169 | - if (isset($server['HTTPS'])) { |
|
177 | + if (isset($server['HTTPS'])) |
|
178 | + { |
|
170 | 179 | $uri = $uri->withScheme($server['HTTPS'] === 'on' ? 'https' : 'http'); |
171 | 180 | } |
172 | 181 | |
173 | - if (isset($server['HTTP_HOST'])) { |
|
174 | - if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) { |
|
182 | + if (isset($server['HTTP_HOST'])) |
|
183 | + { |
|
184 | + if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) |
|
185 | + { |
|
175 | 186 | $uri = $uri->withHost($matches[1])->withPort($matches[2]); |
176 | - } else { |
|
187 | + } |
|
188 | + else |
|
189 | + { |
|
177 | 190 | $uri = $uri->withHost($server['HTTP_HOST']); |
178 | 191 | } |
179 | - } elseif (isset($server['SERVER_NAME'])) { |
|
192 | + } |
|
193 | + elseif (isset($server['SERVER_NAME'])) |
|
194 | + { |
|
180 | 195 | $uri = $uri->withHost($server['SERVER_NAME']); |
181 | 196 | } |
182 | 197 | |
183 | - if (isset($server['SERVER_PORT'])) { |
|
198 | + if (isset($server['SERVER_PORT'])) |
|
199 | + { |
|
184 | 200 | $uri = $uri->withPort($server['SERVER_PORT']); |
185 | 201 | } |
186 | 202 | |
187 | - if (isset($server['REQUEST_URI'])) { |
|
203 | + if (isset($server['REQUEST_URI'])) |
|
204 | + { |
|
188 | 205 | $uri = $uri->withPath(\explode('?', $server['REQUEST_URI'])[0]); |
189 | 206 | } |
190 | 207 | |
191 | - if (isset($server['QUERY_STRING'])) { |
|
208 | + if (isset($server['QUERY_STRING'])) |
|
209 | + { |
|
192 | 210 | $uri = $uri->withQuery($server['QUERY_STRING']); |
193 | 211 | } |
194 | 212 | |
@@ -200,12 +218,17 @@ discard block |
||
200 | 218 | */ |
201 | 219 | private static function getHeadersFromGlobals(): array |
202 | 220 | { |
203 | - if (\function_exists('getallheaders')) { |
|
221 | + if (\function_exists('getallheaders')) |
|
222 | + { |
|
204 | 223 | $headers = getallheaders(); |
205 | - } else { |
|
224 | + } |
|
225 | + else |
|
226 | + { |
|
206 | 227 | $headers = []; |
207 | - foreach ($_SERVER as $name => $value) { |
|
208 | - if (strncmp($name, 'HTTP_', 5) === 0) { |
|
228 | + foreach ($_SERVER as $name => $value) |
|
229 | + { |
|
230 | + if (strncmp($name, 'HTTP_', 5) === 0) |
|
231 | + { |
|
209 | 232 | $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); |
210 | 233 | $headers[$name] = $value; |
211 | 234 | } |
@@ -222,7 +245,8 @@ discard block |
||
222 | 245 | private function getUploadedFilesArray(array $filesArray): array |
223 | 246 | { |
224 | 247 | $files = []; |
225 | - foreach ($filesArray as $class => $info) { |
|
248 | + foreach ($filesArray as $class => $info) |
|
249 | + { |
|
226 | 250 | $files[$class] = []; |
227 | 251 | $this->populateUploadedFileRecursive( |
228 | 252 | $files[$class], |
@@ -250,8 +274,10 @@ discard block |
||
250 | 274 | */ |
251 | 275 | private function populateUploadedFileRecursive(&$files, $names, $tempNames, $types, $sizes, $errors): void |
252 | 276 | { |
253 | - if (\is_array($names)) { |
|
254 | - foreach ($names as $i => $name) { |
|
277 | + if (\is_array($names)) |
|
278 | + { |
|
279 | + foreach ($names as $i => $name) |
|
280 | + { |
|
255 | 281 | $files[$i] = []; |
256 | 282 | $this->populateUploadedFileRecursive( |
257 | 283 | $files[$i], |
@@ -262,10 +288,15 @@ discard block |
||
262 | 288 | $errors[$i] |
263 | 289 | ); |
264 | 290 | } |
265 | - } else { |
|
266 | - try { |
|
291 | + } |
|
292 | + else |
|
293 | + { |
|
294 | + try |
|
295 | + { |
|
267 | 296 | $stream = $this->streamFactory->createStreamFromFile($tempNames); |
268 | - } catch (\RuntimeException $e) { |
|
297 | + } |
|
298 | + catch (\RuntimeException $e) |
|
299 | + { |
|
269 | 300 | $stream = $this->streamFactory->createStream(); |
270 | 301 | } |
271 | 302 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function __construct(array $items = []) |
38 | 38 | { |
39 | - foreach ($items as $item) { |
|
39 | + foreach ($items as $item){ |
|
40 | 40 | $this->addItem($item); |
41 | 41 | } |
42 | 42 | } |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | $header = new static(); |
59 | 59 | |
60 | 60 | $parts = explode(',', $raw); |
61 | - foreach ($parts as $part) { |
|
61 | + foreach ($parts as $part){ |
|
62 | 62 | $part = trim($part); |
63 | - if ($part !== '') { |
|
63 | + if ($part !== ''){ |
|
64 | 64 | $header->addItem($part); |
65 | 65 | } |
66 | 66 | } |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getAll(): array |
105 | 105 | { |
106 | - if (!$this->sorted) { |
|
106 | + if (!$this->sorted){ |
|
107 | 107 | /** |
108 | 108 | * Sort item in descending order. |
109 | 109 | */ |
110 | - uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b) { |
|
110 | + uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b){ |
|
111 | 111 | return self::compare($a, $b) * -1; |
112 | 112 | }); |
113 | 113 | |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | */ |
125 | 125 | private function addItem($item): void |
126 | 126 | { |
127 | - if (is_scalar($item)) { |
|
127 | + if (is_scalar($item)){ |
|
128 | 128 | $item = AcceptHeaderItem::fromString((string)$item); |
129 | 129 | } |
130 | 130 | |
131 | - if (!$item instanceof AcceptHeaderItem) { |
|
131 | + if (!$item instanceof AcceptHeaderItem){ |
|
132 | 132 | throw new AcceptHeaderException(sprintf( |
133 | 133 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
134 | 134 | AcceptHeaderItem::class, |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | } |
138 | 138 | |
139 | 139 | $value = strtolower($item->getValue()); |
140 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
140 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)){ |
|
141 | 141 | $this->sorted = false; |
142 | 142 | $this->items[$value] = $item; |
143 | 143 | } |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | */ |
154 | 154 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
155 | 155 | { |
156 | - if ($a->getQuality() === $b->getQuality()) { |
|
156 | + if ($a->getQuality() === $b->getQuality()){ |
|
157 | 157 | // If quality are same value with more params has more weight. |
158 | - if (count($a->getParams()) === count($b->getParams())) { |
|
158 | + if (count($a->getParams()) === count($b->getParams())){ |
|
159 | 159 | // If quality and params then check for specific type or subtype. |
160 | 160 | // Means */* or * has less weight. |
161 | 161 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -178,11 +178,11 @@ discard block |
||
178 | 178 | private static function compareValue(string $a, string $b): int |
179 | 179 | { |
180 | 180 | // Check "Accept" headers values with it is type and subtype. |
181 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
181 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false){ |
|
182 | 182 | [$typeA, $subtypeA] = explode('/', $a, 2); |
183 | 183 | [$typeB, $subtypeB] = explode('/', $b, 2); |
184 | 184 | |
185 | - if ($typeA === $typeB) { |
|
185 | + if ($typeA === $typeB){ |
|
186 | 186 | return static::compareAtomic($subtypeA, $subtypeB); |
187 | 187 | } |
188 | 188 | |
@@ -199,23 +199,23 @@ discard block |
||
199 | 199 | */ |
200 | 200 | private static function compareAtomic(string $a, string $b): int |
201 | 201 | { |
202 | - if (mb_strpos($a, '*/') === 0) { |
|
202 | + if (mb_strpos($a, '*/') === 0){ |
|
203 | 203 | $a = '*'; |
204 | 204 | } |
205 | 205 | |
206 | - if (mb_strpos($b, '*/') === 0) { |
|
206 | + if (mb_strpos($b, '*/') === 0){ |
|
207 | 207 | $b = '*'; |
208 | 208 | } |
209 | 209 | |
210 | - if (strtolower($a) === strtolower($b)) { |
|
210 | + if (strtolower($a) === strtolower($b)){ |
|
211 | 211 | return 0; |
212 | 212 | } |
213 | 213 | |
214 | - if ($a === '*') { |
|
214 | + if ($a === '*'){ |
|
215 | 215 | return -1; |
216 | 216 | } |
217 | 217 | |
218 | - if ($b === '*') { |
|
218 | + if ($b === '*'){ |
|
219 | 219 | return 1; |
220 | 220 | } |
221 | 221 |
@@ -36,7 +36,8 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function __construct(array $items = []) |
38 | 38 | { |
39 | - foreach ($items as $item) { |
|
39 | + foreach ($items as $item) |
|
40 | + { |
|
40 | 41 | $this->addItem($item); |
41 | 42 | } |
42 | 43 | } |
@@ -58,9 +59,11 @@ discard block |
||
58 | 59 | $header = new static(); |
59 | 60 | |
60 | 61 | $parts = explode(',', $raw); |
61 | - foreach ($parts as $part) { |
|
62 | + foreach ($parts as $part) |
|
63 | + { |
|
62 | 64 | $part = trim($part); |
63 | - if ($part !== '') { |
|
65 | + if ($part !== '') |
|
66 | + { |
|
64 | 67 | $header->addItem($part); |
65 | 68 | } |
66 | 69 | } |
@@ -103,11 +106,13 @@ discard block |
||
103 | 106 | */ |
104 | 107 | public function getAll(): array |
105 | 108 | { |
106 | - if (!$this->sorted) { |
|
109 | + if (!$this->sorted) |
|
110 | + { |
|
107 | 111 | /** |
108 | 112 | * Sort item in descending order. |
109 | 113 | */ |
110 | - uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b) { |
|
114 | + uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b) |
|
115 | + { |
|
111 | 116 | return self::compare($a, $b) * -1; |
112 | 117 | }); |
113 | 118 | |
@@ -124,11 +129,13 @@ discard block |
||
124 | 129 | */ |
125 | 130 | private function addItem($item): void |
126 | 131 | { |
127 | - if (is_scalar($item)) { |
|
132 | + if (is_scalar($item)) |
|
133 | + { |
|
128 | 134 | $item = AcceptHeaderItem::fromString((string)$item); |
129 | 135 | } |
130 | 136 | |
131 | - if (!$item instanceof AcceptHeaderItem) { |
|
137 | + if (!$item instanceof AcceptHeaderItem) |
|
138 | + { |
|
132 | 139 | throw new AcceptHeaderException(sprintf( |
133 | 140 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
134 | 141 | AcceptHeaderItem::class, |
@@ -137,7 +144,8 @@ discard block |
||
137 | 144 | } |
138 | 145 | |
139 | 146 | $value = strtolower($item->getValue()); |
140 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
147 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) |
|
148 | + { |
|
141 | 149 | $this->sorted = false; |
142 | 150 | $this->items[$value] = $item; |
143 | 151 | } |
@@ -153,9 +161,11 @@ discard block |
||
153 | 161 | */ |
154 | 162 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
155 | 163 | { |
156 | - if ($a->getQuality() === $b->getQuality()) { |
|
164 | + if ($a->getQuality() === $b->getQuality()) |
|
165 | + { |
|
157 | 166 | // If quality are same value with more params has more weight. |
158 | - if (count($a->getParams()) === count($b->getParams())) { |
|
167 | + if (count($a->getParams()) === count($b->getParams())) |
|
168 | + { |
|
159 | 169 | // If quality and params then check for specific type or subtype. |
160 | 170 | // Means */* or * has less weight. |
161 | 171 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -178,11 +188,13 @@ discard block |
||
178 | 188 | private static function compareValue(string $a, string $b): int |
179 | 189 | { |
180 | 190 | // Check "Accept" headers values with it is type and subtype. |
181 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
191 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false) |
|
192 | + { |
|
182 | 193 | [$typeA, $subtypeA] = explode('/', $a, 2); |
183 | 194 | [$typeB, $subtypeB] = explode('/', $b, 2); |
184 | 195 | |
185 | - if ($typeA === $typeB) { |
|
196 | + if ($typeA === $typeB) |
|
197 | + { |
|
186 | 198 | return static::compareAtomic($subtypeA, $subtypeB); |
187 | 199 | } |
188 | 200 | |
@@ -199,23 +211,28 @@ discard block |
||
199 | 211 | */ |
200 | 212 | private static function compareAtomic(string $a, string $b): int |
201 | 213 | { |
202 | - if (mb_strpos($a, '*/') === 0) { |
|
214 | + if (mb_strpos($a, '*/') === 0) |
|
215 | + { |
|
203 | 216 | $a = '*'; |
204 | 217 | } |
205 | 218 | |
206 | - if (mb_strpos($b, '*/') === 0) { |
|
219 | + if (mb_strpos($b, '*/') === 0) |
|
220 | + { |
|
207 | 221 | $b = '*'; |
208 | 222 | } |
209 | 223 | |
210 | - if (strtolower($a) === strtolower($b)) { |
|
224 | + if (strtolower($a) === strtolower($b)) |
|
225 | + { |
|
211 | 226 | return 0; |
212 | 227 | } |
213 | 228 | |
214 | - if ($a === '*') { |
|
229 | + if ($a === '*') |
|
230 | + { |
|
215 | 231 | return -1; |
216 | 232 | } |
217 | 233 | |
218 | - if ($b === '*') { |
|
234 | + if ($b === '*') |
|
235 | + { |
|
219 | 236 | return 1; |
220 | 237 | } |
221 | 238 |
@@ -45,17 +45,17 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function __toString(): string |
47 | 47 | { |
48 | - if ($this->value === '') { |
|
48 | + if ($this->value === ''){ |
|
49 | 49 | return ''; |
50 | 50 | } |
51 | 51 | |
52 | 52 | $parts = [$this->value]; |
53 | 53 | |
54 | - if ($this->quality < 1) { |
|
54 | + if ($this->quality < 1){ |
|
55 | 55 | $parts[] = "q=$this->quality"; |
56 | 56 | } |
57 | 57 | |
58 | - foreach ($this->getParams() as $name => $value) { |
|
58 | + foreach ($this->getParams() as $name => $value){ |
|
59 | 59 | $parts[] = "$name=$value"; |
60 | 60 | } |
61 | 61 | |
@@ -76,20 +76,20 @@ discard block |
||
76 | 76 | $quality = 1.0; |
77 | 77 | $params = []; |
78 | 78 | |
79 | - foreach ($elements as $element) { |
|
79 | + foreach ($elements as $element){ |
|
80 | 80 | $parsed = explode('=', trim($element), 2); |
81 | 81 | |
82 | 82 | // Wrong params must be ignored |
83 | - if (count($parsed) !== 2) { |
|
83 | + if (count($parsed) !== 2){ |
|
84 | 84 | continue; |
85 | 85 | } |
86 | 86 | |
87 | 87 | $name = trim($parsed[0]); |
88 | 88 | $value = trim($parsed[1]); |
89 | 89 | |
90 | - if (strcasecmp($name, 'q') === 0) { |
|
90 | + if (strcasecmp($name, 'q') === 0){ |
|
91 | 91 | $quality = (float)$value; |
92 | - } else { |
|
92 | + }else{ |
|
93 | 93 | $params[$name] = $value; |
94 | 94 | } |
95 | 95 | } |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | */ |
179 | 179 | private function setParams(array $params): void |
180 | 180 | { |
181 | - foreach ($params as $name => $value) { |
|
182 | - if (is_numeric($name) || !is_scalar($value)) { |
|
181 | + foreach ($params as $name => $value){ |
|
182 | + if (is_numeric($name) || !is_scalar($value)){ |
|
183 | 183 | continue; |
184 | 184 | } |
185 | 185 | |
186 | 186 | $name = trim($name); |
187 | 187 | $value = trim($value); |
188 | 188 | |
189 | - if ($name === '' || $value === '') { |
|
189 | + if ($name === '' || $value === ''){ |
|
190 | 190 | continue; |
191 | 191 | } |
192 | 192 |
@@ -45,17 +45,20 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function __toString(): string |
47 | 47 | { |
48 | - if ($this->value === '') { |
|
48 | + if ($this->value === '') |
|
49 | + { |
|
49 | 50 | return ''; |
50 | 51 | } |
51 | 52 | |
52 | 53 | $parts = [$this->value]; |
53 | 54 | |
54 | - if ($this->quality < 1) { |
|
55 | + if ($this->quality < 1) |
|
56 | + { |
|
55 | 57 | $parts[] = "q=$this->quality"; |
56 | 58 | } |
57 | 59 | |
58 | - foreach ($this->getParams() as $name => $value) { |
|
60 | + foreach ($this->getParams() as $name => $value) |
|
61 | + { |
|
59 | 62 | $parts[] = "$name=$value"; |
60 | 63 | } |
61 | 64 | |
@@ -76,20 +79,25 @@ discard block |
||
76 | 79 | $quality = 1.0; |
77 | 80 | $params = []; |
78 | 81 | |
79 | - foreach ($elements as $element) { |
|
82 | + foreach ($elements as $element) |
|
83 | + { |
|
80 | 84 | $parsed = explode('=', trim($element), 2); |
81 | 85 | |
82 | 86 | // Wrong params must be ignored |
83 | - if (count($parsed) !== 2) { |
|
87 | + if (count($parsed) !== 2) |
|
88 | + { |
|
84 | 89 | continue; |
85 | 90 | } |
86 | 91 | |
87 | 92 | $name = trim($parsed[0]); |
88 | 93 | $value = trim($parsed[1]); |
89 | 94 | |
90 | - if (strcasecmp($name, 'q') === 0) { |
|
95 | + if (strcasecmp($name, 'q') === 0) |
|
96 | + { |
|
91 | 97 | $quality = (float)$value; |
92 | - } else { |
|
98 | + } |
|
99 | + else |
|
100 | + { |
|
93 | 101 | $params[$name] = $value; |
94 | 102 | } |
95 | 103 | } |
@@ -178,15 +186,18 @@ discard block |
||
178 | 186 | */ |
179 | 187 | private function setParams(array $params): void |
180 | 188 | { |
181 | - foreach ($params as $name => $value) { |
|
182 | - if (is_numeric($name) || !is_scalar($value)) { |
|
189 | + foreach ($params as $name => $value) |
|
190 | + { |
|
191 | + if (is_numeric($name) || !is_scalar($value)) |
|
192 | + { |
|
183 | 193 | continue; |
184 | 194 | } |
185 | 195 | |
186 | 196 | $name = trim($name); |
187 | 197 | $value = trim($value); |
188 | 198 | |
189 | - if ($name === '' || $value === '') { |
|
199 | + if ($name === '' || $value === '') |
|
200 | + { |
|
190 | 201 | continue; |
191 | 202 | } |
192 | 203 |
@@ -29,11 +29,11 @@ |
||
29 | 29 | */ |
30 | 30 | private function writeJson(ResponseInterface $response, $payload, int $code = 200): ResponseInterface |
31 | 31 | { |
32 | - if ($payload instanceof JsonSerializable) { |
|
32 | + if ($payload instanceof JsonSerializable){ |
|
33 | 33 | $payload = $payload->jsonSerialize(); |
34 | 34 | } |
35 | 35 | |
36 | - if (is_array($payload) && isset($payload['status'])) { |
|
36 | + if (is_array($payload) && isset($payload['status'])){ |
|
37 | 37 | $code = $payload['status']; |
38 | 38 | } |
39 | 39 |
@@ -29,11 +29,13 @@ |
||
29 | 29 | */ |
30 | 30 | private function writeJson(ResponseInterface $response, $payload, int $code = 200): ResponseInterface |
31 | 31 | { |
32 | - if ($payload instanceof JsonSerializable) { |
|
32 | + if ($payload instanceof JsonSerializable) |
|
33 | + { |
|
33 | 34 | $payload = $payload->jsonSerialize(); |
34 | 35 | } |
35 | 36 | |
36 | - if (is_array($payload) && isset($payload['status'])) { |
|
37 | + if (is_array($payload) && isset($payload['status'])) |
|
38 | + { |
|
37 | 39 | $code = $payload['status']; |
38 | 40 | } |
39 | 41 |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | */ |
68 | 68 | private function assertNoPreviousOutput(): void |
69 | 69 | { |
70 | - if (headers_sent()) { |
|
70 | + if (headers_sent()){ |
|
71 | 71 | throw new EmitterException('Unable to emit response, headers already send.'); |
72 | 72 | } |
73 | 73 | |
74 | - if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
74 | + if (ob_get_level() > 0 && ob_get_length() > 0){ |
|
75 | 75 | throw new EmitterException('Unable to emit response, found non closed buffered output.'); |
76 | 76 | } |
77 | 77 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | 'HTTP/%s %d%s', |
98 | 98 | $response->getProtocolVersion(), |
99 | 99 | $statusCode, |
100 | - ($reasonPhrase ? ' ' . $reasonPhrase : '') |
|
100 | + ($reasonPhrase ? ' '.$reasonPhrase : '') |
|
101 | 101 | ), true, $statusCode); |
102 | 102 | } |
103 | 103 | |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | { |
116 | 116 | $statusCode = $response->getStatusCode(); |
117 | 117 | |
118 | - foreach ($response->getHeaders() as $header => $values) { |
|
118 | + foreach ($response->getHeaders() as $header => $values){ |
|
119 | 119 | $name = $this->filterHeader($header); |
120 | 120 | $first = $name === 'Set-Cookie' ? false : true; |
121 | - foreach ($values as $value) { |
|
121 | + foreach ($values as $value){ |
|
122 | 122 | header(sprintf( |
123 | 123 | '%s: %s', |
124 | 124 | $name, |
@@ -67,11 +67,13 @@ discard block |
||
67 | 67 | */ |
68 | 68 | private function assertNoPreviousOutput(): void |
69 | 69 | { |
70 | - if (headers_sent()) { |
|
70 | + if (headers_sent()) |
|
71 | + { |
|
71 | 72 | throw new EmitterException('Unable to emit response, headers already send.'); |
72 | 73 | } |
73 | 74 | |
74 | - if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
75 | + if (ob_get_level() > 0 && ob_get_length() > 0) |
|
76 | + { |
|
75 | 77 | throw new EmitterException('Unable to emit response, found non closed buffered output.'); |
76 | 78 | } |
77 | 79 | } |
@@ -115,10 +117,12 @@ discard block |
||
115 | 117 | { |
116 | 118 | $statusCode = $response->getStatusCode(); |
117 | 119 | |
118 | - foreach ($response->getHeaders() as $header => $values) { |
|
120 | + foreach ($response->getHeaders() as $header => $values) |
|
121 | + { |
|
119 | 122 | $name = $this->filterHeader($header); |
120 | 123 | $first = $name === 'Set-Cookie' ? false : true; |
121 | - foreach ($values as $value) { |
|
124 | + foreach ($values as $value) |
|
125 | + { |
|
122 | 126 | header(sprintf( |
123 | 127 | '%s: %s', |
124 | 128 | $name, |
@@ -73,12 +73,12 @@ |
||
73 | 73 | */ |
74 | 74 | public function handle(Request $request): Response |
75 | 75 | { |
76 | - if (empty($this->handler)) { |
|
76 | + if (empty($this->handler)){ |
|
77 | 77 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
78 | 78 | } |
79 | 79 | |
80 | 80 | $position = $this->position++; |
81 | - if (isset($this->middleware[$position])) { |
|
81 | + if (isset($this->middleware[$position])){ |
|
82 | 82 | return $this->middleware[$position]->process($request, $this); |
83 | 83 | } |
84 | 84 |
@@ -73,16 +73,19 @@ |
||
73 | 73 | */ |
74 | 74 | public function handle(Request $request): Response |
75 | 75 | { |
76 | - if (empty($this->handler)) { |
|
76 | + if (empty($this->handler)) |
|
77 | + { |
|
77 | 78 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
78 | 79 | } |
79 | 80 | |
80 | 81 | $position = $this->position++; |
81 | - if (isset($this->middleware[$position])) { |
|
82 | + if (isset($this->middleware[$position])) |
|
83 | + { |
|
82 | 84 | return $this->middleware[$position]->process($request, $this); |
83 | 85 | } |
84 | 86 | |
85 | - return $this->scope->runScope([Request::class => $request], function () use ($request) { |
|
87 | + return $this->scope->runScope([Request::class => $request], function () use ($request) |
|
88 | + { |
|
86 | 89 | return $this->handler->handle($request); |
87 | 90 | }); |
88 | 91 | } |
@@ -34,11 +34,11 @@ |
||
34 | 34 | */ |
35 | 35 | public function __construct(?int $code = null, string $message = '', ?\Throwable $previous = null) |
36 | 36 | { |
37 | - if (empty($code) && empty($this->code)) { |
|
37 | + if (empty($code) && empty($this->code)){ |
|
38 | 38 | $code = self::BAD_DATA; |
39 | 39 | } |
40 | 40 | |
41 | - if (empty($message)) { |
|
41 | + if (empty($message)){ |
|
42 | 42 | $message = "Http Error - {$code}"; |
43 | 43 | } |
44 | 44 |
@@ -34,11 +34,13 @@ |
||
34 | 34 | */ |
35 | 35 | public function __construct(?int $code = null, string $message = '', ?\Throwable $previous = null) |
36 | 36 | { |
37 | - if (empty($code) && empty($this->code)) { |
|
37 | + if (empty($code) && empty($this->code)) |
|
38 | + { |
|
38 | 39 | $code = self::BAD_DATA; |
39 | 40 | } |
40 | 41 | |
41 | - if (empty($message)) { |
|
42 | + if (empty($message)) |
|
43 | + { |
|
42 | 44 | $message = "Http Error - {$code}"; |
43 | 45 | } |
44 | 46 |
@@ -32,7 +32,7 @@ |
||
32 | 32 | */ |
33 | 33 | public function getFilename(string $name): ?string |
34 | 34 | { |
35 | - if (!empty($file = $this->get($name)) && !$file->getError()) { |
|
35 | + if (!empty($file = $this->get($name)) && !$file->getError()){ |
|
36 | 36 | return StreamWrapper::getFilename($file->getStream()); |
37 | 37 | } |
38 | 38 |
@@ -32,7 +32,8 @@ |
||
32 | 32 | */ |
33 | 33 | public function getFilename(string $name): ?string |
34 | 34 | { |
35 | - if (!empty($file = $this->get($name)) && !$file->getError()) { |
|
35 | + if (!empty($file = $this->get($name)) && !$file->getError()) |
|
36 | + { |
|
36 | 37 | return StreamWrapper::getFilename($file->getStream()); |
37 | 38 | } |
38 | 39 |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function all(): array |
59 | 59 | { |
60 | - try { |
|
60 | + try{ |
|
61 | 61 | return $this->dotGet(''); |
62 | - } catch (DotNotFoundException $e) { |
|
62 | + }catch (DotNotFoundException $e){ |
|
63 | 63 | return []; |
64 | 64 | } |
65 | 65 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | { |
86 | 86 | $result = array_intersect_key($this->all(), array_flip($keys)); |
87 | 87 | ; |
88 | - if (!$fill) { |
|
88 | + if (!$fill){ |
|
89 | 89 | return $result; |
90 | 90 | } |
91 | 91 | |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function has(string $name): bool |
110 | 110 | { |
111 | - try { |
|
111 | + try{ |
|
112 | 112 | $this->dotGet($name); |
113 | - } catch (DotNotFoundException $e) { |
|
113 | + }catch (DotNotFoundException $e){ |
|
114 | 114 | return false; |
115 | 115 | } |
116 | 116 | |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function get(string $name, $default = null) |
136 | 136 | { |
137 | - try { |
|
137 | + try{ |
|
138 | 138 | return $this->dotGet($name); |
139 | - } catch (DotNotFoundException $e) { |
|
139 | + }catch (DotNotFoundException $e){ |
|
140 | 140 | return $default; |
141 | 141 | } |
142 | 142 | } |
@@ -174,15 +174,15 @@ discard block |
||
174 | 174 | $data = $this->data; |
175 | 175 | |
176 | 176 | //Generating path relative to a given name and prefix |
177 | - $path = (!empty($this->prefix) ? $this->prefix . '.' : '') . $name; |
|
178 | - if (empty($path)) { |
|
177 | + $path = (!empty($this->prefix) ? $this->prefix.'.' : '').$name; |
|
178 | + if (empty($path)){ |
|
179 | 179 | return $data; |
180 | 180 | } |
181 | 181 | |
182 | 182 | $path = explode('.', rtrim($path, '.')); |
183 | 183 | |
184 | - foreach ($path as $step) { |
|
185 | - if (!is_array($data) || !array_key_exists($step, $data)) { |
|
184 | + foreach ($path as $step){ |
|
185 | + if (!is_array($data) || !array_key_exists($step, $data)){ |
|
186 | 186 | throw new DotNotFoundException("Unable to find requested element '{$name}'"); |
187 | 187 | } |
188 | 188 |
@@ -57,9 +57,12 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function all(): array |
59 | 59 | { |
60 | - try { |
|
60 | + try |
|
61 | + { |
|
61 | 62 | return $this->dotGet(''); |
62 | - } catch (DotNotFoundException $e) { |
|
63 | + } |
|
64 | + catch (DotNotFoundException $e) |
|
65 | + { |
|
63 | 66 | return []; |
64 | 67 | } |
65 | 68 | } |
@@ -85,7 +88,8 @@ discard block |
||
85 | 88 | { |
86 | 89 | $result = array_intersect_key($this->all(), array_flip($keys)); |
87 | 90 | ; |
88 | - if (!$fill) { |
|
91 | + if (!$fill) |
|
92 | + { |
|
89 | 93 | return $result; |
90 | 94 | } |
91 | 95 | |
@@ -108,9 +112,12 @@ discard block |
||
108 | 112 | */ |
109 | 113 | public function has(string $name): bool |
110 | 114 | { |
111 | - try { |
|
115 | + try |
|
116 | + { |
|
112 | 117 | $this->dotGet($name); |
113 | - } catch (DotNotFoundException $e) { |
|
118 | + } |
|
119 | + catch (DotNotFoundException $e) |
|
120 | + { |
|
114 | 121 | return false; |
115 | 122 | } |
116 | 123 | |
@@ -134,9 +141,12 @@ discard block |
||
134 | 141 | */ |
135 | 142 | public function get(string $name, $default = null) |
136 | 143 | { |
137 | - try { |
|
144 | + try |
|
145 | + { |
|
138 | 146 | return $this->dotGet($name); |
139 | - } catch (DotNotFoundException $e) { |
|
147 | + } |
|
148 | + catch (DotNotFoundException $e) |
|
149 | + { |
|
140 | 150 | return $default; |
141 | 151 | } |
142 | 152 | } |
@@ -175,14 +185,17 @@ discard block |
||
175 | 185 | |
176 | 186 | //Generating path relative to a given name and prefix |
177 | 187 | $path = (!empty($this->prefix) ? $this->prefix . '.' : '') . $name; |
178 | - if (empty($path)) { |
|
188 | + if (empty($path)) |
|
189 | + { |
|
179 | 190 | return $data; |
180 | 191 | } |
181 | 192 | |
182 | 193 | $path = explode('.', rtrim($path, '.')); |
183 | 194 | |
184 | - foreach ($path as $step) { |
|
185 | - if (!is_array($data) || !array_key_exists($step, $data)) { |
|
195 | + foreach ($path as $step) |
|
196 | + { |
|
197 | + if (!is_array($data) || !array_key_exists($step, $data)) |
|
198 | + { |
|
186 | 199 | throw new DotNotFoundException("Unable to find requested element '{$name}'"); |
187 | 200 | } |
188 | 201 |