Passed
Pull Request — master (#1059)
by Maxim
15:44 queued 04:26
created
src/Http/src/Request/InputManager.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         private readonly ContainerInterface $container,
118 118
         /** @invisible */
119 119
         HttpConfig $config = new HttpConfig()
120
-    ) {
120
+    ){
121 121
         $this->bagAssociations = \array_merge($this->bagAssociations, $config->getInputBags());
122 122
     }
123 123
 
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
     {
147 147
         $input = clone $this;
148 148
 
149
-        if ($add) {
150
-            $input->prefix .= '.' . $prefix;
149
+        if ($add){
150
+            $input->prefix .= '.'.$prefix;
151 151
             $input->prefix = \trim($input->prefix, '.');
152
-        } else {
152
+        }else{
153 153
             $input->prefix = $prefix;
154 154
         }
155 155
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 
166 166
         return match (true) {
167 167
             empty($path) => '/',
168
-            $path[0] !== '/' => '/' . $path,
168
+            $path[0] !== '/' => '/'.$path,
169 169
             default => $path
170 170
         };
171 171
     }
@@ -185,9 +185,9 @@  discard block
 block discarded – undo
185 185
      */
186 186
     public function request(): Request
187 187
     {
188
-        try {
188
+        try{
189 189
             $request = $this->container->get(Request::class);
190
-        } catch (ContainerExceptionInterface $e) {
190
+        }catch (ContainerExceptionInterface $e){
191 191
             throw new ScopeException(
192 192
                 'Unable to get `ServerRequestInterface` in active container scope',
193 193
                 $e->getCode(),
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
         }
197 197
 
198 198
         // Flushing input state
199
-        if ($this->request !== $request) {
199
+        if ($this->request !== $request){
200 200
             $this->bags = [];
201 201
             $this->request = $request;
202 202
         }
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
         $position = \strrpos($header, 'Bearer ');
215 215
 
216
-        if ($position !== false) {
216
+        if ($position !== false){
217 217
             $header = \substr($header, $position + 7);
218 218
 
219 219
             return \str_contains($header, ',')
@@ -267,16 +267,16 @@  discard block
 block discarded – undo
267 267
     public function isJsonExpected(bool $softMatch = false): bool
268 268
     {
269 269
         $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept'));
270
-        foreach ($this->jsonTypes as $jsonType) {
271
-            if ($acceptHeader->has($jsonType)) {
270
+        foreach ($this->jsonTypes as $jsonType){
271
+            if ($acceptHeader->has($jsonType)){
272 272
                 return true;
273 273
             }
274 274
         }
275 275
 
276
-        if ($softMatch) {
277
-            foreach ($acceptHeader->getAll() as $item) {
276
+        if ($softMatch){
277
+            foreach ($acceptHeader->getAll() as $item){
278 278
                 $itemValue = \strtolower($item->getValue());
279
-                if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) {
279
+                if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')){
280 280
                     return true;
281 281
                 }
282 282
             }
@@ -315,19 +315,19 @@  discard block
 block discarded – undo
315 315
         // ensure proper request association
316 316
         $this->request();
317 317
 
318
-        if (isset($this->bags[$name])) {
318
+        if (isset($this->bags[$name])){
319 319
             return $this->bags[$name];
320 320
         }
321 321
 
322 322
         $definition = $this->findBagDefinition($name);
323
-        if (!$definition) {
323
+        if (!$definition){
324 324
             throw new InputException(\sprintf("Undefined input bag '%s'", $name));
325 325
         }
326 326
 
327 327
         $class = $definition['class'];
328 328
         $data = \call_user_func([$this->request(), $definition['source']]);
329 329
 
330
-        if (!\is_array($data)) {
330
+        if (!\is_array($data)){
331 331
             $data = (array)$data;
332 332
         }
333 333
 
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 
337 337
     public function hasBag(string $name): bool
338 338
     {
339
-        if (isset($this->bags[$name])) {
339
+        if (isset($this->bags[$name])){
340 340
             return true;
341 341
         }
342 342
 
@@ -356,12 +356,12 @@  discard block
 block discarded – undo
356 356
      */
357 357
     private function findBagDefinition(string $name): ?array
358 358
     {
359
-        if (isset($this->bagAssociations[$name])) {
359
+        if (isset($this->bagAssociations[$name])){
360 360
             return $this->bagAssociations[$name];
361 361
         }
362 362
 
363
-        foreach ($this->bagAssociations as $bag) {
364
-            if (isset($bag['alias']) && $bag['alias'] === $name) {
363
+        foreach ($this->bagAssociations as $bag){
364
+            if (isset($bag['alias']) && $bag['alias'] === $name){
365 365
                 return $bag;
366 366
             }
367 367
         }
Please login to merge, or discard this patch.
Braces   +38 added lines, -18 removed lines patch added patch discarded remove patch
@@ -146,10 +146,13 @@  discard block
 block discarded – undo
146 146
     {
147 147
         $input = clone $this;
148 148
 
149
-        if ($add) {
149
+        if ($add)
150
+        {
150 151
             $input->prefix .= '.' . $prefix;
151 152
             $input->prefix = \trim($input->prefix, '.');
152
-        } else {
153
+        }
154
+        else
155
+        {
153 156
             $input->prefix = $prefix;
154 157
         }
155 158
 
@@ -185,9 +188,12 @@  discard block
 block discarded – undo
185 188
      */
186 189
     public function request(): Request
187 190
     {
188
-        try {
191
+        try
192
+        {
189 193
             $request = $this->container->get(Request::class);
190
-        } catch (ContainerExceptionInterface $e) {
194
+        }
195
+        catch (ContainerExceptionInterface $e)
196
+        {
191 197
             throw new ScopeException(
192 198
                 'Unable to get `ServerRequestInterface` in active container scope',
193 199
                 $e->getCode(),
@@ -196,7 +202,8 @@  discard block
 block discarded – undo
196 202
         }
197 203
 
198 204
         // Flushing input state
199
-        if ($this->request !== $request) {
205
+        if ($this->request !== $request)
206
+        {
200 207
             $this->bags = [];
201 208
             $this->request = $request;
202 209
         }
@@ -213,7 +220,8 @@  discard block
 block discarded – undo
213 220
 
214 221
         $position = \strrpos($header, 'Bearer ');
215 222
 
216
-        if ($position !== false) {
223
+        if ($position !== false)
224
+        {
217 225
             $header = \substr($header, $position + 7);
218 226
 
219 227
             return \str_contains($header, ',')
@@ -267,16 +275,21 @@  discard block
 block discarded – undo
267 275
     public function isJsonExpected(bool $softMatch = false): bool
268 276
     {
269 277
         $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept'));
270
-        foreach ($this->jsonTypes as $jsonType) {
271
-            if ($acceptHeader->has($jsonType)) {
278
+        foreach ($this->jsonTypes as $jsonType)
279
+        {
280
+            if ($acceptHeader->has($jsonType))
281
+            {
272 282
                 return true;
273 283
             }
274 284
         }
275 285
 
276
-        if ($softMatch) {
277
-            foreach ($acceptHeader->getAll() as $item) {
286
+        if ($softMatch)
287
+        {
288
+            foreach ($acceptHeader->getAll() as $item)
289
+            {
278 290
                 $itemValue = \strtolower($item->getValue());
279
-                if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) {
291
+                if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json'))
292
+                {
280 293
                     return true;
281 294
                 }
282 295
             }
@@ -315,19 +328,22 @@  discard block
 block discarded – undo
315 328
         // ensure proper request association
316 329
         $this->request();
317 330
 
318
-        if (isset($this->bags[$name])) {
331
+        if (isset($this->bags[$name]))
332
+        {
319 333
             return $this->bags[$name];
320 334
         }
321 335
 
322 336
         $definition = $this->findBagDefinition($name);
323
-        if (!$definition) {
337
+        if (!$definition)
338
+        {
324 339
             throw new InputException(\sprintf("Undefined input bag '%s'", $name));
325 340
         }
326 341
 
327 342
         $class = $definition['class'];
328 343
         $data = \call_user_func([$this->request(), $definition['source']]);
329 344
 
330
-        if (!\is_array($data)) {
345
+        if (!\is_array($data))
346
+        {
331 347
             $data = (array)$data;
332 348
         }
333 349
 
@@ -336,7 +352,8 @@  discard block
 block discarded – undo
336 352
 
337 353
     public function hasBag(string $name): bool
338 354
     {
339
-        if (isset($this->bags[$name])) {
355
+        if (isset($this->bags[$name]))
356
+        {
340 357
             return true;
341 358
         }
342 359
 
@@ -356,12 +373,15 @@  discard block
 block discarded – undo
356 373
      */
357 374
     private function findBagDefinition(string $name): ?array
358 375
     {
359
-        if (isset($this->bagAssociations[$name])) {
376
+        if (isset($this->bagAssociations[$name]))
377
+        {
360 378
             return $this->bagAssociations[$name];
361 379
         }
362 380
 
363
-        foreach ($this->bagAssociations as $bag) {
364
-            if (isset($bag['alias']) && $bag['alias'] === $name) {
381
+        foreach ($this->bagAssociations as $bag)
382
+        {
383
+            if (isset($bag['alias']) && $bag['alias'] === $name)
384
+            {
365 385
                 return $bag;
366 386
             }
367 387
         }
Please login to merge, or discard this patch.
src/Http/src/Request/ServerBag.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,14 +10,14 @@
 block discarded – undo
10 10
  */
11 11
 final class ServerBag extends InputBag
12 12
 {
13
-    public function has(int|string $name): bool
13
+    public function has(int | string $name): bool
14 14
     {
15
-        return parent::has($this->normalize((string) $name));
15
+        return parent::has($this->normalize((string)$name));
16 16
     }
17 17
 
18
-    public function get(int|string $name, mixed $default = null): mixed
18
+    public function get(int | string $name, mixed $default = null): mixed
19 19
     {
20
-        return parent::get($this->normalize((string) $name), $default);
20
+        return parent::get($this->normalize((string)$name), $default);
21 21
     }
22 22
 
23 23
     public function fetch(array $keys, bool $fill = false, mixed $filler = null): array
Please login to merge, or discard this patch.
src/Http/src/Request/FilesBag.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,9 +20,9 @@
 block discarded – undo
20 20
     /**
21 21
      * Locale local filename (virtual filename) associated with UploadedFile resource.
22 22
      */
23
-    public function getFilename(int|string $name): ?string
23
+    public function getFilename(int | string $name): ?string
24 24
     {
25
-        if (!empty($file = $this->get($name)) && !$file->getError()) {
25
+        if (!empty($file = $this->get($name)) && !$file->getError()){
26 26
             return StreamWrapper::getFilename($file->getStream());
27 27
         }
28 28
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,8 @@
 block discarded – undo
22 22
      */
23 23
     public function getFilename(int|string $name): ?string
24 24
     {
25
-        if (!empty($file = $this->get($name)) && !$file->getError()) {
25
+        if (!empty($file = $this->get($name)) && !$file->getError())
26
+        {
26 27
             return StreamWrapper::getFilename($file->getStream());
27 28
         }
28 29
 
Please login to merge, or discard this patch.
src/Http/src/Request/HeadersBag.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -10,19 +10,19 @@  discard block
 block discarded – undo
10 10
  */
11 11
 final class HeadersBag extends InputBag
12 12
 {
13
-    public function has(int|string $name): bool
13
+    public function has(int | string $name): bool
14 14
     {
15
-        return parent::has($this->normalize((string) $name));
15
+        return parent::has($this->normalize((string)$name));
16 16
     }
17 17
 
18 18
     /**
19 19
      * @param false|string $implode Implode header lines, false to return header as array.
20 20
      */
21
-    public function get(int|string $name, mixed $default = null, bool|string $implode = ','): array|string|null
21
+    public function get(int | string $name, mixed $default = null, bool | string $implode = ','): array | string | null
22 22
     {
23
-        $value = parent::get($this->normalize((string) $name), $default);
23
+        $value = parent::get($this->normalize((string)$name), $default);
24 24
 
25
-        if (\is_string($implode) && !empty($implode) && \is_array($value)) {
25
+        if (\is_string($implode) && !empty($implode) && \is_array($value)){
26 26
             return \implode($implode, $value);
27 27
         }
28 28
 
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
      */
35 35
     public function fetch(array $keys, bool $fill = false, mixed $filler = null, ?string $implode = ','): array
36 36
     {
37
-        $keys = \array_map(fn (string $header): string => $this->normalize($header), $keys);
37
+        $keys = \array_map(fn (string $header) : string => $this->normalize($header), $keys);
38 38
 
39 39
         $values = parent::fetch($keys, $fill, $filler);
40 40
 
41
-        if (!empty($implode)) {
42
-            foreach ($values as &$value) {
41
+        if (!empty($implode)){
42
+            foreach ($values as &$value){
43 43
                 $value = \implode($implode, $value);
44 44
                 unset($value);
45 45
             }
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,7 +22,8 @@  discard block
 block discarded – undo
22 22
     {
23 23
         $value = parent::get($this->normalize((string) $name), $default);
24 24
 
25
-        if (\is_string($implode) && !empty($implode) && \is_array($value)) {
25
+        if (\is_string($implode) && !empty($implode) && \is_array($value))
26
+        {
26 27
             return \implode($implode, $value);
27 28
         }
28 29
 
@@ -38,8 +39,10 @@  discard block
 block discarded – undo
38 39
 
39 40
         $values = parent::fetch($keys, $fill, $filler);
40 41
 
41
-        if (!empty($implode)) {
42
-            foreach ($values as &$value) {
42
+        if (!empty($implode))
43
+        {
44
+            foreach ($values as &$value)
45
+            {
43 46
                 $value = \implode($implode, $value);
44 47
                 unset($value);
45 48
             }
Please login to merge, or discard this patch.
src/Http/src/Middleware/ErrorHandlerMiddleware/EnvSuppressErrors.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
 {
11 11
     public function __construct(
12 12
         private DebugMode $debugMode
13
-    ) {
13
+    ){
14 14
     }
15 15
 
16 16
     public function suppressed(): bool
Please login to merge, or discard this patch.
src/Http/src/Middleware/JsonPayloadMiddleware.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
      */
22 22
     public function __construct(
23 23
         private readonly JsonPayloadConfig $config
24
-    ) {
24
+    ){
25 25
     }
26 26
 
27 27
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
28 28
     {
29
-        if ($this->isJsonPayload($request)) {
29
+        if ($this->isJsonPayload($request)){
30 30
             $body = (string)$request->getBody();
31
-            if ($body !== '') {
31
+            if ($body !== ''){
32 32
                 $request = $request->withParsedBody(\json_decode($body, true));
33
-                if (\json_last_error() !== 0) {
33
+                if (\json_last_error() !== 0){
34 34
                     throw new ClientException(400, 'invalid json payload');
35 35
                 }
36 36
             }
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
     {
44 44
         $contentType = $request->getHeaderLine('Content-Type');
45 45
 
46
-        foreach ($this->config->getContentTypes() as $allowedType) {
47
-            if (\stripos($contentType, $allowedType) === 0) {
46
+        foreach ($this->config->getContentTypes() as $allowedType){
47
+            if (\stripos($contentType, $allowedType) === 0){
48 48
                 return true;
49 49
             }
50 50
         }
Please login to merge, or discard this patch.
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,11 +26,14 @@  discard block
 block discarded – undo
26 26
 
27 27
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
28 28
     {
29
-        if ($this->isJsonPayload($request)) {
29
+        if ($this->isJsonPayload($request))
30
+        {
30 31
             $body = (string)$request->getBody();
31
-            if ($body !== '') {
32
+            if ($body !== '')
33
+            {
32 34
                 $request = $request->withParsedBody(\json_decode($body, true));
33
-                if (\json_last_error() !== 0) {
35
+                if (\json_last_error() !== 0)
36
+                {
34 37
                     throw new ClientException(400, 'invalid json payload');
35 38
                 }
36 39
             }
@@ -43,8 +46,10 @@  discard block
 block discarded – undo
43 46
     {
44 47
         $contentType = $request->getHeaderLine('Content-Type');
45 48
 
46
-        foreach ($this->config->getContentTypes() as $allowedType) {
47
-            if (\stripos($contentType, $allowedType) === 0) {
49
+        foreach ($this->config->getContentTypes() as $allowedType)
50
+        {
51
+            if (\stripos($contentType, $allowedType) === 0)
52
+            {
48 53
                 return true;
49 54
             }
50 55
         }
Please login to merge, or discard this patch.
src/Http/src/CallableHandler.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     public function __construct(
25 25
         callable $callable,
26 26
         private readonly ResponseFactoryInterface $responseFactory
27
-    ) {
27
+    ){
28 28
         $this->callable = $callable;
29 29
     }
30 30
 
@@ -39,21 +39,21 @@  discard block
 block discarded – undo
39 39
         $output = $result = null;
40 40
 
41 41
         $response = $this->responseFactory->createResponse(200);
42
-        try {
42
+        try{
43 43
             $result = \call_user_func($this->callable, $request, $response);
44
-        } catch (\Throwable $e) {
44
+        }catch (\Throwable $e){
45 45
             \ob_get_clean();
46 46
             throw $e;
47
-        } finally {
48
-            while (\ob_get_level() > $outputLevel + 1) {
49
-                $output = \ob_get_clean() . $output;
47
+        }finally{
48
+            while (\ob_get_level() > $outputLevel + 1){
49
+                $output = \ob_get_clean().$output;
50 50
             }
51 51
         }
52 52
 
53 53
         return $this->wrapResponse(
54 54
             $response,
55 55
             $result,
56
-            \ob_get_clean() . $output
56
+            \ob_get_clean().$output
57 57
         );
58 58
     }
59 59
 
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
      */
67 67
     private function wrapResponse(Response $response, mixed $result = null, string $output = ''): Response
68 68
     {
69
-        if ($result instanceof Response) {
70
-            if (!empty($output) && $result->getBody()->isWritable()) {
69
+        if ($result instanceof Response){
70
+            if (!empty($output) && $result->getBody()->isWritable()){
71 71
                 $result->getBody()->write($output);
72 72
             }
73 73
 
74 74
             return $result;
75 75
         }
76 76
 
77
-        if (\is_array($result) || $result instanceof \JsonSerializable) {
77
+        if (\is_array($result) || $result instanceof \JsonSerializable){
78 78
             $response = $this->writeJson($response, $result);
79
-        } else {
79
+        }else{
80 80
             $response->getBody()->write((string)$result);
81 81
         }
82 82
 
Please login to merge, or discard this patch.
Braces   +19 added lines, -8 removed lines patch added patch discarded remove patch
@@ -39,13 +39,19 @@  discard block
 block discarded – undo
39 39
         $output = $result = null;
40 40
 
41 41
         $response = $this->responseFactory->createResponse(200);
42
-        try {
42
+        try
43
+        {
43 44
             $result = \call_user_func($this->callable, $request, $response);
44
-        } catch (\Throwable $e) {
45
+        }
46
+        catch (\Throwable $e)
47
+        {
45 48
             \ob_get_clean();
46 49
             throw $e;
47
-        } finally {
48
-            while (\ob_get_level() > $outputLevel + 1) {
50
+        }
51
+        finally
52
+        {
53
+            while (\ob_get_level() > $outputLevel + 1)
54
+            {
49 55
                 $output = \ob_get_clean() . $output;
50 56
             }
51 57
         }
@@ -66,17 +72,22 @@  discard block
 block discarded – undo
66 72
      */
67 73
     private function wrapResponse(Response $response, mixed $result = null, string $output = ''): Response
68 74
     {
69
-        if ($result instanceof Response) {
70
-            if (!empty($output) && $result->getBody()->isWritable()) {
75
+        if ($result instanceof Response)
76
+        {
77
+            if (!empty($output) && $result->getBody()->isWritable())
78
+            {
71 79
                 $result->getBody()->write($output);
72 80
             }
73 81
 
74 82
             return $result;
75 83
         }
76 84
 
77
-        if (\is_array($result) || $result instanceof \JsonSerializable) {
85
+        if (\is_array($result) || $result instanceof \JsonSerializable)
86
+        {
78 87
             $response = $this->writeJson($response, $result);
79
-        } else {
88
+        }
89
+        else
90
+        {
80 91
             $response->getBody()->write((string)$result);
81 92
         }
82 93
 
Please login to merge, or discard this patch.
src/Http/src/Header/AcceptHeader.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      */
27 27
     public function __construct(array $items = [])
28 28
     {
29
-        foreach ($items as $item) {
29
+        foreach ($items as $item){
30 30
             $this->addItem($item);
31 31
         }
32 32
     }
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
         $header = new static();
42 42
 
43 43
         $parts = \explode(',', $raw);
44
-        foreach ($parts as $part) {
44
+        foreach ($parts as $part){
45 45
             $part = \trim($part);
46
-            if ($part !== '') {
46
+            if ($part !== ''){
47 47
                 $header->addItem($part);
48 48
             }
49 49
         }
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         return $header;
52 52
     }
53 53
 
54
-    public function add(AcceptHeaderItem|string $item): self
54
+    public function add(AcceptHeaderItem | string $item): self
55 55
     {
56 56
         $header = clone $this;
57 57
         $header->addItem($item);
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      */
75 75
     public function getAll(): array
76 76
     {
77
-        if (!$this->sorted) {
77
+        if (!$this->sorted){
78 78
             /**
79 79
              * Sort item in descending order.
80 80
              */
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
     /**
90 90
      * Add new item to list.
91 91
      */
92
-    private function addItem(AcceptHeaderItem|string $item): void
92
+    private function addItem(AcceptHeaderItem | string $item): void
93 93
     {
94
-        if (\is_string($item)) {
94
+        if (\is_string($item)){
95 95
             $item = AcceptHeaderItem::fromString($item);
96 96
         }
97 97
 
98 98
         $value = \strtolower($item->getValue());
99
-        if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) {
99
+        if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)){
100 100
             $this->sorted = false;
101 101
             $this->items[$value] = $item;
102 102
         }
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
      * Compare to header items, witch one is preferable.
107 107
      * Return 1 if first value preferable or -1 if second, 0 in case of same weight.
108 108
      */
109
-    private static function compare(AcceptHeaderItem|string $a, AcceptHeaderItem|string $b): int
109
+    private static function compare(AcceptHeaderItem | string $a, AcceptHeaderItem | string $b): int
110 110
     {
111
-        if ($a->getQuality() === $b->getQuality()) {
111
+        if ($a->getQuality() === $b->getQuality()){
112 112
             // If quality are same value with more params has more weight.
113
-            if (\count($a->getParams()) === \count($b->getParams())) {
113
+            if (\count($a->getParams()) === \count($b->getParams())){
114 114
                 // If quality and params then check for specific type or subtype.
115 115
                 // Means */* or * has less weight.
116 116
                 return static::compareValue($a->getValue(), $b->getValue());
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
     private static function compareValue(string $a, string $b): int
130 130
     {
131 131
         // Check "Accept" headers values with it is type and subtype.
132
-        if (\str_contains($a, '/') && \str_contains($b, '/')) {
132
+        if (\str_contains($a, '/') && \str_contains($b, '/')){
133 133
             [$typeA, $subtypeA] = \explode('/', $a, 2);
134 134
             [$typeB, $subtypeB] = \explode('/', $b, 2);
135 135
 
136
-            if ($typeA === $typeB) {
136
+            if ($typeA === $typeB){
137 137
                 return static::compareAtomic($subtypeA, $subtypeB);
138 138
             }
139 139
 
@@ -145,23 +145,23 @@  discard block
 block discarded – undo
145 145
 
146 146
     private static function compareAtomic(string $a, string $b): int
147 147
     {
148
-        if (\mb_strpos($a, '*/') === 0) {
148
+        if (\mb_strpos($a, '*/') === 0){
149 149
             $a = '*';
150 150
         }
151 151
 
152
-        if (\mb_strpos($b, '*/') === 0) {
152
+        if (\mb_strpos($b, '*/') === 0){
153 153
             $b = '*';
154 154
         }
155 155
 
156
-        if (\strtolower($a) === \strtolower($b)) {
156
+        if (\strtolower($a) === \strtolower($b)){
157 157
             return 0;
158 158
         }
159 159
 
160
-        if ($a === '*') {
160
+        if ($a === '*'){
161 161
             return -1;
162 162
         }
163 163
 
164
-        if ($b === '*') {
164
+        if ($b === '*'){
165 165
             return 1;
166 166
         }
167 167
 
Please login to merge, or discard this patch.
Braces   +30 added lines, -15 removed lines patch added patch discarded remove patch
@@ -26,7 +26,8 @@  discard block
 block discarded – undo
26 26
      */
27 27
     public function __construct(array $items = [])
28 28
     {
29
-        foreach ($items as $item) {
29
+        foreach ($items as $item)
30
+        {
30 31
             $this->addItem($item);
31 32
         }
32 33
     }
@@ -41,9 +42,11 @@  discard block
 block discarded – undo
41 42
         $header = new static();
42 43
 
43 44
         $parts = \explode(',', $raw);
44
-        foreach ($parts as $part) {
45
+        foreach ($parts as $part)
46
+        {
45 47
             $part = \trim($part);
46
-            if ($part !== '') {
48
+            if ($part !== '')
49
+            {
47 50
                 $header->addItem($part);
48 51
             }
49 52
         }
@@ -74,7 +77,8 @@  discard block
 block discarded – undo
74 77
      */
75 78
     public function getAll(): array
76 79
     {
77
-        if (!$this->sorted) {
80
+        if (!$this->sorted)
81
+        {
78 82
             /**
79 83
              * Sort item in descending order.
80 84
              */
@@ -91,12 +95,14 @@  discard block
 block discarded – undo
91 95
      */
92 96
     private function addItem(AcceptHeaderItem|string $item): void
93 97
     {
94
-        if (\is_string($item)) {
98
+        if (\is_string($item))
99
+        {
95 100
             $item = AcceptHeaderItem::fromString($item);
96 101
         }
97 102
 
98 103
         $value = \strtolower($item->getValue());
99
-        if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) {
104
+        if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1))
105
+        {
100 106
             $this->sorted = false;
101 107
             $this->items[$value] = $item;
102 108
         }
@@ -108,9 +114,11 @@  discard block
 block discarded – undo
108 114
      */
109 115
     private static function compare(AcceptHeaderItem|string $a, AcceptHeaderItem|string $b): int
110 116
     {
111
-        if ($a->getQuality() === $b->getQuality()) {
117
+        if ($a->getQuality() === $b->getQuality())
118
+        {
112 119
             // If quality are same value with more params has more weight.
113
-            if (\count($a->getParams()) === \count($b->getParams())) {
120
+            if (\count($a->getParams()) === \count($b->getParams()))
121
+            {
114 122
                 // If quality and params then check for specific type or subtype.
115 123
                 // Means */* or * has less weight.
116 124
                 return static::compareValue($a->getValue(), $b->getValue());
@@ -129,11 +137,13 @@  discard block
 block discarded – undo
129 137
     private static function compareValue(string $a, string $b): int
130 138
     {
131 139
         // Check "Accept" headers values with it is type and subtype.
132
-        if (\str_contains($a, '/') && \str_contains($b, '/')) {
140
+        if (\str_contains($a, '/') && \str_contains($b, '/'))
141
+        {
133 142
             [$typeA, $subtypeA] = \explode('/', $a, 2);
134 143
             [$typeB, $subtypeB] = \explode('/', $b, 2);
135 144
 
136
-            if ($typeA === $typeB) {
145
+            if ($typeA === $typeB)
146
+            {
137 147
                 return static::compareAtomic($subtypeA, $subtypeB);
138 148
             }
139 149
 
@@ -145,23 +155,28 @@  discard block
 block discarded – undo
145 155
 
146 156
     private static function compareAtomic(string $a, string $b): int
147 157
     {
148
-        if (\mb_strpos($a, '*/') === 0) {
158
+        if (\mb_strpos($a, '*/') === 0)
159
+        {
149 160
             $a = '*';
150 161
         }
151 162
 
152
-        if (\mb_strpos($b, '*/') === 0) {
163
+        if (\mb_strpos($b, '*/') === 0)
164
+        {
153 165
             $b = '*';
154 166
         }
155 167
 
156
-        if (\strtolower($a) === \strtolower($b)) {
168
+        if (\strtolower($a) === \strtolower($b))
169
+        {
157 170
             return 0;
158 171
         }
159 172
 
160
-        if ($a === '*') {
173
+        if ($a === '*')
174
+        {
161 175
             return -1;
162 176
         }
163 177
 
164
-        if ($b === '*') {
178
+        if ($b === '*')
179
+        {
165 180
             return 1;
166 181
         }
167 182
 
Please login to merge, or discard this patch.
src/Http/src/Header/AcceptHeaderItem.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -27,17 +27,17 @@  discard block
 block discarded – undo
27 27
 
28 28
     public function __toString(): string
29 29
     {
30
-        if ($this->value === '') {
30
+        if ($this->value === ''){
31 31
             return '';
32 32
         }
33 33
 
34 34
         $parts = [$this->value];
35 35
 
36
-        if ($this->quality < 1) {
36
+        if ($this->quality < 1){
37 37
             $parts[] = \sprintf('q=%s', $this->quality);
38 38
         }
39 39
 
40
-        foreach ($this->getParams() as $name => $value) {
40
+        foreach ($this->getParams() as $name => $value){
41 41
             $parts[] = \sprintf('%s=%s', $name, $value);
42 42
         }
43 43
 
@@ -55,20 +55,20 @@  discard block
 block discarded – undo
55 55
         $quality = 1.0;
56 56
         $params = [];
57 57
 
58
-        foreach ($elements as $element) {
58
+        foreach ($elements as $element){
59 59
             $parsed = \explode('=', \trim($element), 2);
60 60
 
61 61
             // Wrong params must be ignored
62
-            if (\count($parsed) !== 2) {
62
+            if (\count($parsed) !== 2){
63 63
                 continue;
64 64
             }
65 65
 
66 66
             $name = \trim($parsed[0]);
67 67
             $value = \trim($parsed[1]);
68 68
 
69
-            if (\strcasecmp($name, 'q') === 0) {
69
+            if (\strcasecmp($name, 'q') === 0){
70 70
                 $quality = (float)$value;
71
-            } else {
71
+            }else{
72 72
                 $params[$name] = $value;
73 73
             }
74 74
         }
@@ -127,15 +127,15 @@  discard block
 block discarded – undo
127 127
 
128 128
     private function setParams(array $params): void
129 129
     {
130
-        foreach ($params as $name => $value) {
131
-            if (\is_numeric($name) || !\is_scalar($value)) {
130
+        foreach ($params as $name => $value){
131
+            if (\is_numeric($name) || !\is_scalar($value)){
132 132
                 continue;
133 133
             }
134 134
 
135 135
             $name = \trim($name);
136 136
             $value = \trim((string)$value);
137 137
 
138
-            if ($name === '' || $value === '') {
138
+            if ($name === '' || $value === ''){
139 139
                 continue;
140 140
             }
141 141
 
Please login to merge, or discard this patch.
Braces   +21 added lines, -10 removed lines patch added patch discarded remove patch
@@ -27,17 +27,20 @@  discard block
 block discarded – undo
27 27
 
28 28
     public function __toString(): string
29 29
     {
30
-        if ($this->value === '') {
30
+        if ($this->value === '')
31
+        {
31 32
             return '';
32 33
         }
33 34
 
34 35
         $parts = [$this->value];
35 36
 
36
-        if ($this->quality < 1) {
37
+        if ($this->quality < 1)
38
+        {
37 39
             $parts[] = \sprintf('q=%s', $this->quality);
38 40
         }
39 41
 
40
-        foreach ($this->getParams() as $name => $value) {
42
+        foreach ($this->getParams() as $name => $value)
43
+        {
41 44
             $parts[] = \sprintf('%s=%s', $name, $value);
42 45
         }
43 46
 
@@ -55,20 +58,25 @@  discard block
 block discarded – undo
55 58
         $quality = 1.0;
56 59
         $params = [];
57 60
 
58
-        foreach ($elements as $element) {
61
+        foreach ($elements as $element)
62
+        {
59 63
             $parsed = \explode('=', \trim($element), 2);
60 64
 
61 65
             // Wrong params must be ignored
62
-            if (\count($parsed) !== 2) {
66
+            if (\count($parsed) !== 2)
67
+            {
63 68
                 continue;
64 69
             }
65 70
 
66 71
             $name = \trim($parsed[0]);
67 72
             $value = \trim($parsed[1]);
68 73
 
69
-            if (\strcasecmp($name, 'q') === 0) {
74
+            if (\strcasecmp($name, 'q') === 0)
75
+            {
70 76
                 $quality = (float)$value;
71
-            } else {
77
+            }
78
+            else
79
+            {
72 80
                 $params[$name] = $value;
73 81
             }
74 82
         }
@@ -127,15 +135,18 @@  discard block
 block discarded – undo
127 135
 
128 136
     private function setParams(array $params): void
129 137
     {
130
-        foreach ($params as $name => $value) {
131
-            if (\is_numeric($name) || !\is_scalar($value)) {
138
+        foreach ($params as $name => $value)
139
+        {
140
+            if (\is_numeric($name) || !\is_scalar($value))
141
+            {
132 142
                 continue;
133 143
             }
134 144
 
135 145
             $name = \trim($name);
136 146
             $value = \trim((string)$value);
137 147
 
138
-            if ($name === '' || $value === '') {
148
+            if ($name === '' || $value === '')
149
+            {
139 150
                 continue;
140 151
             }
141 152
 
Please login to merge, or discard this patch.