Passed
Pull Request — master (#1221)
by Aleksei
12:41
created
src/Http/src/Header/AcceptHeaderItem.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -36,20 +36,20 @@  discard block
 block discarded – undo
36 36
         $quality = 1.0;
37 37
         $params = [];
38 38
 
39
-        foreach ($elements as $element) {
39
+        foreach ($elements as $element){
40 40
             $parsed = \explode('=', \trim($element), 2);
41 41
 
42 42
             // Wrong params must be ignored
43
-            if (\count($parsed) !== 2) {
43
+            if (\count($parsed) !== 2){
44 44
                 continue;
45 45
             }
46 46
 
47 47
             $name = \trim($parsed[0]);
48 48
             $value = \trim($parsed[1]);
49 49
 
50
-            if (\strcasecmp($name, 'q') === 0) {
51
-                $quality = (float) $value;
52
-            } else {
50
+            if (\strcasecmp($name, 'q') === 0){
51
+                $quality = (float)$value;
52
+            }else{
53 53
                 $params[$name] = $value;
54 54
             }
55 55
         }
@@ -98,17 +98,17 @@  discard block
 block discarded – undo
98 98
 
99 99
     public function __toString(): string
100 100
     {
101
-        if ($this->value === '') {
101
+        if ($this->value === ''){
102 102
             return '';
103 103
         }
104 104
 
105 105
         $parts = [$this->value];
106 106
 
107
-        if ($this->quality < 1) {
107
+        if ($this->quality < 1){
108 108
             $parts[] = \sprintf('q=%s', $this->quality);
109 109
         }
110 110
 
111
-        foreach ($this->getParams() as $name => $value) {
111
+        foreach ($this->getParams() as $name => $value){
112 112
             $parts[] = \sprintf('%s=%s', $name, $value);
113 113
         }
114 114
 
@@ -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
-            $value = \trim((string) $value);
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
@@ -36,20 +36,25 @@  discard block
 block discarded – undo
36 36
         $quality = 1.0;
37 37
         $params = [];
38 38
 
39
-        foreach ($elements as $element) {
39
+        foreach ($elements as $element)
40
+        {
40 41
             $parsed = \explode('=', \trim($element), 2);
41 42
 
42 43
             // Wrong params must be ignored
43
-            if (\count($parsed) !== 2) {
44
+            if (\count($parsed) !== 2)
45
+            {
44 46
                 continue;
45 47
             }
46 48
 
47 49
             $name = \trim($parsed[0]);
48 50
             $value = \trim($parsed[1]);
49 51
 
50
-            if (\strcasecmp($name, 'q') === 0) {
52
+            if (\strcasecmp($name, 'q') === 0)
53
+            {
51 54
                 $quality = (float) $value;
52
-            } else {
55
+            }
56
+            else
57
+            {
53 58
                 $params[$name] = $value;
54 59
             }
55 60
         }
@@ -98,17 +103,20 @@  discard block
 block discarded – undo
98 103
 
99 104
     public function __toString(): string
100 105
     {
101
-        if ($this->value === '') {
106
+        if ($this->value === '')
107
+        {
102 108
             return '';
103 109
         }
104 110
 
105 111
         $parts = [$this->value];
106 112
 
107
-        if ($this->quality < 1) {
113
+        if ($this->quality < 1)
114
+        {
108 115
             $parts[] = \sprintf('q=%s', $this->quality);
109 116
         }
110 117
 
111
-        foreach ($this->getParams() as $name => $value) {
118
+        foreach ($this->getParams() as $name => $value)
119
+        {
112 120
             $parts[] = \sprintf('%s=%s', $name, $value);
113 121
         }
114 122
 
@@ -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.
src/Http/src/LazyPipeline.php 2 patches
Braces   +11 added lines, -5 removed lines patch added patch discarded remove patch
@@ -41,7 +41,8 @@  discard block
 block discarded – undo
41 41
     public function __construct(
42 42
         #[Proxy] private readonly ContainerInterface $container,
43 43
         private readonly ?EventDispatcherInterface $dispatcher = null,
44
-    ) {}
44
+    ) {
45
+}
45 46
 
46 47
     /**
47 48
      * Add middleware to the pipeline.
@@ -93,9 +94,11 @@  discard block
 block discarded – undo
93 94
 
94 95
         $previousRequest = $currentRequest->get();
95 96
         $currentRequest->set($request);
96
-        try {
97
+        try
98
+        {
97 99
             // There is no middleware to process, let's pass the request to the handler
98
-            if (!\array_key_exists($this->position, $this->middleware)) {
100
+            if (!\array_key_exists($this->position, $this->middleware))
101
+            {
99 102
                 return $this->handler->handle($request);
100 103
             }
101 104
 
@@ -109,7 +112,8 @@  discard block
 block discarded – undo
109 112
                 ? \sprintf('%s=%s', $this->middleware[$this->position], $middleware::class)
110 113
                 : $middleware::class;
111 114
             // Init a tracing span when the pipeline starts
112
-            if ($span === null) {
115
+            if ($span === null)
116
+            {
113 117
                 /** @var TracerInterface $tracer */
114 118
                 $tracer = $this->container->get(TracerInterface::class);
115 119
                 return $tracer->trace(
@@ -127,7 +131,9 @@  discard block
 block discarded – undo
127 131
             $span->setAttribute('http.middleware', $middlewares);
128 132
 
129 133
             return $middleware->process($request, $this->next($span));
130
-        } finally {
134
+        }
135
+        finally
136
+        {
131 137
             $currentRequest->set($previousRequest);
132 138
         }
133 139
     }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
     public function __construct(
42 42
         #[Proxy] private readonly ContainerInterface $container,
43 43
         private readonly ?EventDispatcherInterface $dispatcher = null,
44
-    ) {}
44
+    ){}
45 45
 
46 46
     /**
47 47
      * Add middleware to the pipeline.
48 48
      *
49 49
      * @param MiddlewareInterface|Autowire|non-empty-string ...$middleware List of middleware or its definition.
50 50
      */
51
-    public function withAddedMiddleware(MiddlewareInterface|Autowire|string ...$middleware): self
51
+    public function withAddedMiddleware(MiddlewareInterface | Autowire | string ...$middleware): self
52 52
     {
53 53
         $pipeline = clone $this;
54 54
         $pipeline->middleware = \array_merge($pipeline->middleware, $middleware);
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      *
61 61
      * @param MiddlewareInterface ...$middleware List of middleware or its definition.
62 62
      */
63
-    public function withMiddleware(MiddlewareInterface|Autowire|string ...$middleware): self
63
+    public function withMiddleware(MiddlewareInterface | Autowire | string ...$middleware): self
64 64
     {
65 65
         $pipeline = clone $this;
66 66
         $pipeline->middleware = $middleware;
@@ -93,9 +93,9 @@  discard block
 block discarded – undo
93 93
 
94 94
         $previousRequest = $currentRequest->get();
95 95
         $currentRequest->set($request);
96
-        try {
96
+        try{
97 97
             // There is no middleware to process, let's pass the request to the handler
98
-            if (!\array_key_exists($this->position, $this->middleware)) {
98
+            if (!\array_key_exists($this->position, $this->middleware)){
99 99
                 return $this->handler->handle($request);
100 100
             }
101 101
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
                 ? \sprintf('%s=%s', $this->middleware[$this->position], $middleware::class)
110 110
                 : $middleware::class;
111 111
             // Init a tracing span when the pipeline starts
112
-            if ($span === null) {
112
+            if ($span === null){
113 113
                 /** @var TracerInterface $tracer */
114 114
                 $tracer = $this->container->get(TracerInterface::class);
115 115
                 return $tracer->trace(
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
             $span->setAttribute('http.middleware', $middlewares);
128 128
 
129 129
             return $middleware->process($request, $this->next($span));
130
-        } finally {
130
+        }finally{
131 131
             $currentRequest->set($previousRequest);
132 132
         }
133 133
     }
Please login to merge, or discard this patch.
src/Http/src/Event/MiddlewareProcessing.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,5 +12,5 @@
 block discarded – undo
12 12
     public function __construct(
13 13
         public readonly ServerRequestInterface $request,
14 14
         public readonly MiddlewareInterface $middleware,
15
-    ) {}
15
+    ){}
16 16
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,5 +12,6 @@
 block discarded – undo
12 12
     public function __construct(
13 13
         public readonly ServerRequestInterface $request,
14 14
         public readonly MiddlewareInterface $middleware,
15
-    ) {}
15
+    ) {
16
+}
16 17
 }
Please login to merge, or discard this patch.
src/Http/src/Event/RequestReceived.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,5 +10,5 @@
 block discarded – undo
10 10
 {
11 11
     public function __construct(
12 12
         public readonly ServerRequestInterface $request,
13
-    ) {}
13
+    ){}
14 14
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,5 +10,6 @@
 block discarded – undo
10 10
 {
11 11
     public function __construct(
12 12
         public readonly ServerRequestInterface $request,
13
-    ) {}
13
+    ) {
14
+}
14 15
 }
Please login to merge, or discard this patch.
src/Http/src/Event/RequestHandled.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,5 +12,5 @@
 block discarded – undo
12 12
     public function __construct(
13 13
         public readonly ServerRequestInterface $request,
14 14
         public readonly ResponseInterface $response,
15
-    ) {}
15
+    ){}
16 16
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,5 +12,6 @@
 block discarded – undo
12 12
     public function __construct(
13 13
         public readonly ServerRequestInterface $request,
14 14
         public readonly ResponseInterface $response,
15
-    ) {}
15
+    ) {
16
+}
16 17
 }
Please login to merge, or discard this patch.
src/Http/src/ErrorHandler/PlainRenderer.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,17 +16,17 @@
 block discarded – undo
16 16
 {
17 17
     public function __construct(
18 18
         private readonly ResponseFactoryInterface $responseFactory,
19
-    ) {}
19
+    ){}
20 20
 
21 21
     public function renderException(Request $request, int $code, \Throwable $exception): Response
22 22
     {
23 23
         $acceptItems = AcceptHeader::fromString($request->getHeaderLine('Accept'))->getAll();
24 24
 
25 25
         $response = $this->responseFactory->createResponse($code);
26
-        if ($acceptItems && $acceptItems[0]->getValue() === 'application/json') {
26
+        if ($acceptItems && $acceptItems[0]->getValue() === 'application/json'){
27 27
             $response = $response->withHeader('Content-Type', 'application/json; charset=UTF-8');
28 28
             $response->getBody()->write(\json_encode(['status' => $code]));
29
-        } else {
29
+        }else{
30 30
             $response->getBody()->write("Error code: {$code}");
31 31
         }
32 32
 
Please login to merge, or discard this patch.
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,17 +16,21 @@
 block discarded – undo
16 16
 {
17 17
     public function __construct(
18 18
         private readonly ResponseFactoryInterface $responseFactory,
19
-    ) {}
19
+    ) {
20
+}
20 21
 
21 22
     public function renderException(Request $request, int $code, \Throwable $exception): Response
22 23
     {
23 24
         $acceptItems = AcceptHeader::fromString($request->getHeaderLine('Accept'))->getAll();
24 25
 
25 26
         $response = $this->responseFactory->createResponse($code);
26
-        if ($acceptItems && $acceptItems[0]->getValue() === 'application/json') {
27
+        if ($acceptItems && $acceptItems[0]->getValue() === 'application/json')
28
+        {
27 29
             $response = $response->withHeader('Content-Type', 'application/json; charset=UTF-8');
28 30
             $response->getBody()->write(\json_encode(['status' => $code]));
29
-        } else {
31
+        }
32
+        else
33
+        {
30 34
             $response->getBody()->write("Error code: {$code}");
31 35
         }
32 36
 
Please login to merge, or discard this patch.
src/Http/src/Middleware/ErrorHandlerMiddleware.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
         private readonly ResponseFactoryInterface $responseFactory,
33 33
         private readonly ExceptionHandlerInterface $errorHandler,
34 34
         private readonly Verbosity $verbosity = Verbosity::VERBOSE,
35
-    ) {}
35
+    ){}
36 36
 
37 37
     /**
38 38
      * @psalm-suppress UnusedVariable
@@ -40,17 +40,17 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function process(Request $request, Handler $handler): Response
42 42
     {
43
-        try {
43
+        try{
44 44
             return $handler->handle($request);
45
-        } catch (ClientException|RouterException $e) {
45
+        }catch (ClientException | RouterException $e){
46 46
             $code = $e instanceof ClientException ? $e->getCode() : 404;
47
-        } catch (\Throwable $e) {
47
+        }catch (\Throwable $e){
48 48
             $code = 500;
49 49
         }
50 50
 
51 51
         $this->errorHandler->report($e);
52 52
 
53
-        if (!$this->suppressErrors->suppressed()) {
53
+        if (!$this->suppressErrors->suppressed()){
54 54
             return $this->renderError($request, $e, $code);
55 55
         }
56 56
 
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
 
69 69
         [$format, $renderer] = $this->getRenderer($this->errorHandler, $request);
70 70
 
71
-        if ($format !== null) {
72
-            $response = $response->withHeader('Content-Type', $format . '; charset=UTF-8');
71
+        if ($format !== null){
72
+            $response = $response->withHeader('Content-Type', $format.'; charset=UTF-8');
73 73
         }
74 74
 
75 75
         $response->getBody()->write(
76
-            (string) $renderer?->render(
76
+            (string)$renderer?->render(
77 77
                 exception: $e,
78 78
                 verbosity: $this->verbosity,
79 79
                 format: $format,
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
      */
89 89
     private function getRenderer(ExceptionHandlerInterface $handler, Request $request): array
90 90
     {
91
-        if ($request->hasHeader('Accept')) {
91
+        if ($request->hasHeader('Accept')){
92 92
             $acceptItems = AcceptHeader::fromString($request->getHeaderLine('Accept'))->getAll();
93
-            foreach ($acceptItems as $item) {
93
+            foreach ($acceptItems as $item){
94 94
                 $format = $item->getValue();
95 95
                 $renderer = $handler->getRenderer($format);
96
-                if ($renderer !== null) {
96
+                if ($renderer !== null){
97 97
                     return [$format, $renderer];
98 98
                 }
99 99
             }
Please login to merge, or discard this patch.
Braces   +20 added lines, -9 removed lines patch added patch discarded remove patch
@@ -32,7 +32,8 @@  discard block
 block discarded – undo
32 32
         private readonly ResponseFactoryInterface $responseFactory,
33 33
         private readonly ExceptionHandlerInterface $errorHandler,
34 34
         private readonly Verbosity $verbosity = Verbosity::VERBOSE,
35
-    ) {}
35
+    ) {
36
+}
36 37
 
37 38
     /**
38 39
      * @psalm-suppress UnusedVariable
@@ -40,17 +41,23 @@  discard block
 block discarded – undo
40 41
      */
41 42
     public function process(Request $request, Handler $handler): Response
42 43
     {
43
-        try {
44
+        try
45
+        {
44 46
             return $handler->handle($request);
45
-        } catch (ClientException|RouterException $e) {
47
+        }
48
+        catch (ClientException|RouterException $e)
49
+        {
46 50
             $code = $e instanceof ClientException ? $e->getCode() : 404;
47
-        } catch (\Throwable $e) {
51
+        }
52
+        catch (\Throwable $e)
53
+        {
48 54
             $code = 500;
49 55
         }
50 56
 
51 57
         $this->errorHandler->report($e);
52 58
 
53
-        if (!$this->suppressErrors->suppressed()) {
59
+        if (!$this->suppressErrors->suppressed())
60
+        {
54 61
             return $this->renderError($request, $e, $code);
55 62
         }
56 63
 
@@ -68,7 +75,8 @@  discard block
 block discarded – undo
68 75
 
69 76
         [$format, $renderer] = $this->getRenderer($this->errorHandler, $request);
70 77
 
71
-        if ($format !== null) {
78
+        if ($format !== null)
79
+        {
72 80
             $response = $response->withHeader('Content-Type', $format . '; charset=UTF-8');
73 81
         }
74 82
 
@@ -88,12 +96,15 @@  discard block
 block discarded – undo
88 96
      */
89 97
     private function getRenderer(ExceptionHandlerInterface $handler, Request $request): array
90 98
     {
91
-        if ($request->hasHeader('Accept')) {
99
+        if ($request->hasHeader('Accept'))
100
+        {
92 101
             $acceptItems = AcceptHeader::fromString($request->getHeaderLine('Accept'))->getAll();
93
-            foreach ($acceptItems as $item) {
102
+            foreach ($acceptItems as $item)
103
+            {
94 104
                 $format = $item->getValue();
95 105
                 $renderer = $handler->getRenderer($format);
96
-                if ($renderer !== null) {
106
+                if ($renderer !== null)
107
+                {
97 108
                     return [$format, $renderer];
98 109
                 }
99 110
             }
Please login to merge, or discard this patch.
src/Http/src/Middleware/ErrorHandlerMiddleware/EnvSuppressErrors.php 2 patches
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 readonly DebugMode $debugMode,
13
-    ) {}
13
+    ){}
14 14
 
15 15
     public function suppressed(): bool
16 16
     {
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,8 @@
 block discarded – undo
10 10
 {
11 11
     public function __construct(
12 12
         private readonly DebugMode $debugMode,
13
-    ) {}
13
+    ) {
14
+}
14 15
 
15 16
     public function suppressed(): bool
16 17
     {
Please login to merge, or discard this patch.
src/Http/src/Middleware/JsonPayloadMiddleware.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -21,15 +21,15 @@  discard block
 block discarded – undo
21 21
      */
22 22
     public function __construct(
23 23
         private readonly JsonPayloadConfig $config,
24
-    ) {}
24
+    ){}
25 25
 
26 26
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
27 27
     {
28
-        if ($this->isJsonPayload($request)) {
29
-            $body = (string) $request->getBody();
30
-            if ($body !== '') {
28
+        if ($this->isJsonPayload($request)){
29
+            $body = (string)$request->getBody();
30
+            if ($body !== ''){
31 31
                 $request = $request->withParsedBody(\json_decode($body, true));
32
-                if (\json_last_error() !== 0) {
32
+                if (\json_last_error() !== 0){
33 33
                     throw new ClientException(400, 'invalid json payload');
34 34
                 }
35 35
             }
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
     {
43 43
         $contentType = $request->getHeaderLine('Content-Type');
44 44
 
45
-        foreach ($this->config->getContentTypes() as $allowedType) {
46
-            if (\stripos($contentType, $allowedType) === 0) {
45
+        foreach ($this->config->getContentTypes() as $allowedType){
46
+            if (\stripos($contentType, $allowedType) === 0){
47 47
                 return true;
48 48
             }
49 49
         }
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -21,15 +21,19 @@  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
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
27 28
     {
28
-        if ($this->isJsonPayload($request)) {
29
+        if ($this->isJsonPayload($request))
30
+        {
29 31
             $body = (string) $request->getBody();
30
-            if ($body !== '') {
32
+            if ($body !== '')
33
+            {
31 34
                 $request = $request->withParsedBody(\json_decode($body, true));
32
-                if (\json_last_error() !== 0) {
35
+                if (\json_last_error() !== 0)
36
+                {
33 37
                     throw new ClientException(400, 'invalid json payload');
34 38
                 }
35 39
             }
@@ -42,8 +46,10 @@  discard block
 block discarded – undo
42 46
     {
43 47
         $contentType = $request->getHeaderLine('Content-Type');
44 48
 
45
-        foreach ($this->config->getContentTypes() as $allowedType) {
46
-            if (\stripos($contentType, $allowedType) === 0) {
49
+        foreach ($this->config->getContentTypes() as $allowedType)
50
+        {
51
+            if (\stripos($contentType, $allowedType) === 0)
52
+            {
47 53
                 return true;
48 54
             }
49 55
         }
Please login to merge, or discard this patch.