Passed
Push — master ( 2291e3...cd7158 )
by Anton
03:34
created
src/Router/src/AbstractRoute.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,12 +65,12 @@
 block discarded – undo
65 65
      */
66 66
     public function match(Request $request): ?RouteInterface
67 67
     {
68
-        if (!in_array(strtoupper($request->getMethod()), $this->getVerbs(), true)) {
68
+        if (!in_array(strtoupper($request->getMethod()), $this->getVerbs(), true)){
69 69
             return null;
70 70
         }
71 71
 
72 72
         $matches = $this->uriHandler->match($request->getUri(), $this->defaults);
73
-        if ($matches === null) {
73
+        if ($matches === null){
74 74
             return null;
75 75
         }
76 76
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,12 +65,14 @@
 block discarded – undo
65 65
      */
66 66
     public function match(Request $request): ?RouteInterface
67 67
     {
68
-        if (!in_array(strtoupper($request->getMethod()), $this->getVerbs(), true)) {
68
+        if (!in_array(strtoupper($request->getMethod()), $this->getVerbs(), true))
69
+        {
69 70
             return null;
70 71
         }
71 72
 
72 73
         $matches = $this->uriHandler->match($request->getUri(), $this->defaults);
73
-        if ($matches === null) {
74
+        if ($matches === null)
75
+        {
74 76
             return null;
75 77
         }
76 78
 
Please login to merge, or discard this patch.
src/Router/src/CoreHandler.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         CoreInterface $core,
61 61
         ScopeInterface $scope,
62 62
         ResponseFactoryInterface $responseFactory
63
-    ) {
63
+    ){
64 64
         $this->core = $core;
65 65
         $this->scope = $scope;
66 66
         $this->responseFactory = $responseFactory;
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function handle(Request $request): Response
105 105
     {
106
-        if ($this->controller === null) {
106
+        if ($this->controller === null){
107 107
             throw new HandlerException('Controller and action pair is not set');
108 108
         }
109 109
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         $output = $result = null;
114 114
 
115 115
         $response = $this->responseFactory->createResponse(200);
116
-        try {
116
+        try{
117 117
             // run the core withing PSR-7 Request/Response scope
118 118
             $result = $this->scope->runScope(
119 119
                 [
@@ -128,22 +128,22 @@  discard block
 block discarded – undo
128 128
                     );
129 129
                 }
130 130
             );
131
-        } catch (ControllerException $e) {
131
+        }catch (ControllerException $e){
132 132
             ob_get_clean();
133 133
             throw $this->mapException($e);
134
-        } catch (\Throwable $e) {
134
+        }catch (\Throwable $e){
135 135
             ob_get_clean();
136 136
             throw $e;
137
-        } finally {
138
-            while (ob_get_level() > $outputLevel + 1) {
139
-                $output = ob_get_clean() . $output;
137
+        }finally{
138
+            while (ob_get_level() > $outputLevel + 1){
139
+                $output = ob_get_clean().$output;
140 140
             }
141 141
         }
142 142
 
143 143
         return $this->wrapResponse(
144 144
             $response,
145 145
             $result,
146
-            ob_get_clean() . $output
146
+            ob_get_clean().$output
147 147
         );
148 148
     }
149 149
 
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
      */
154 154
     private function getAction(Request $request): string
155 155
     {
156
-        if ($this->verbActions) {
157
-            return strtolower($request->getMethod()) . ucfirst($this->action);
156
+        if ($this->verbActions){
157
+            return strtolower($request->getMethod()).ucfirst($this->action);
158 158
         }
159 159
 
160 160
         return $this->action;
@@ -170,17 +170,17 @@  discard block
 block discarded – undo
170 170
      */
171 171
     private function wrapResponse(Response $response, $result = null, string $output = ''): Response
172 172
     {
173
-        if ($result instanceof Response) {
174
-            if ($output !== '' && $result->getBody()->isWritable()) {
173
+        if ($result instanceof Response){
174
+            if ($output !== '' && $result->getBody()->isWritable()){
175 175
                 $result->getBody()->write($output);
176 176
             }
177 177
 
178 178
             return $result;
179 179
         }
180 180
 
181
-        if (is_array($result) || $result instanceof \JsonSerializable) {
181
+        if (is_array($result) || $result instanceof \JsonSerializable){
182 182
             $response = $this->writeJson($response, $result);
183
-        } else {
183
+        }else{
184 184
             $response->getBody()->write((string)$result);
185 185
         }
186 186
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
      */
199 199
     private function mapException(ControllerException $exception): ClientException
200 200
     {
201
-        switch ($exception->getCode()) {
201
+        switch ($exception->getCode()){
202 202
             case ControllerException::BAD_ACTION:
203 203
             case ControllerException::NOT_FOUND:
204 204
                 return new NotFoundException($exception->getMessage());
Please login to merge, or discard this patch.
Braces   +30 added lines, -13 removed lines patch added patch discarded remove patch
@@ -103,7 +103,8 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function handle(Request $request): Response
105 105
     {
106
-        if ($this->controller === null) {
106
+        if ($this->controller === null)
107
+        {
107 108
             throw new HandlerException('Controller and action pair is not set');
108 109
         }
109 110
 
@@ -113,14 +114,16 @@  discard block
 block discarded – undo
113 114
         $output = $result = null;
114 115
 
115 116
         $response = $this->responseFactory->createResponse(200);
116
-        try {
117
+        try
118
+        {
117 119
             // run the core withing PSR-7 Request/Response scope
118 120
             $result = $this->scope->runScope(
119 121
                 [
120 122
                     Request::class  => $request,
121 123
                     Response::class => $response
122 124
                 ],
123
-                function () use ($request) {
125
+                function () use ($request)
126
+                {
124 127
                     return $this->core->callAction(
125 128
                         $this->controller,
126 129
                         $this->getAction($request),
@@ -128,14 +131,21 @@  discard block
 block discarded – undo
128 131
                     );
129 132
                 }
130 133
             );
131
-        } catch (ControllerException $e) {
134
+        }
135
+        catch (ControllerException $e)
136
+        {
132 137
             ob_get_clean();
133 138
             throw $this->mapException($e);
134
-        } catch (\Throwable $e) {
139
+        }
140
+        catch (\Throwable $e)
141
+        {
135 142
             ob_get_clean();
136 143
             throw $e;
137
-        } finally {
138
-            while (ob_get_level() > $outputLevel + 1) {
144
+        }
145
+        finally
146
+        {
147
+            while (ob_get_level() > $outputLevel + 1)
148
+            {
139 149
                 $output = ob_get_clean() . $output;
140 150
             }
141 151
         }
@@ -153,7 +163,8 @@  discard block
 block discarded – undo
153 163
      */
154 164
     private function getAction(Request $request): string
155 165
     {
156
-        if ($this->verbActions) {
166
+        if ($this->verbActions)
167
+        {
157 168
             return strtolower($request->getMethod()) . ucfirst($this->action);
158 169
         }
159 170
 
@@ -170,17 +181,22 @@  discard block
 block discarded – undo
170 181
      */
171 182
     private function wrapResponse(Response $response, $result = null, string $output = ''): Response
172 183
     {
173
-        if ($result instanceof Response) {
174
-            if ($output !== '' && $result->getBody()->isWritable()) {
184
+        if ($result instanceof Response)
185
+        {
186
+            if ($output !== '' && $result->getBody()->isWritable())
187
+            {
175 188
                 $result->getBody()->write($output);
176 189
             }
177 190
 
178 191
             return $result;
179 192
         }
180 193
 
181
-        if (is_array($result) || $result instanceof \JsonSerializable) {
194
+        if (is_array($result) || $result instanceof \JsonSerializable)
195
+        {
182 196
             $response = $this->writeJson($response, $result);
183
-        } else {
197
+        }
198
+        else
199
+        {
184 200
             $response->getBody()->write((string)$result);
185 201
         }
186 202
 
@@ -198,7 +214,8 @@  discard block
 block discarded – undo
198 214
      */
199 215
     private function mapException(ControllerException $exception): ClientException
200 216
     {
201
-        switch ($exception->getCode()) {
217
+        switch ($exception->getCode())
218
+        {
202 219
             case ControllerException::BAD_ACTION:
203 220
             case ControllerException::NOT_FOUND:
204 221
                 return new NotFoundException($exception->getMessage());
Please login to merge, or discard this patch.
src/Router/src/UriHandler.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
         'integer' => '\d+',
33 33
         'uuid'    => '0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}'
34 34
     ];
35
-    private const URI_FIXERS       = [
35
+    private const URI_FIXERS = [
36 36
         '[]'  => '',
37 37
         '[/]' => '',
38 38
         '['   => '',
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     public function __construct(
79 79
         UriFactoryInterface $uriFactory,
80 80
         SlugifyInterface $slugify = null
81
-    ) {
81
+    ){
82 82
         $this->uriFactory = $uriFactory;
83 83
         $this->slugify = $slugify ?? new Slugify();
84 84
     }
@@ -167,12 +167,12 @@  discard block
 block discarded – undo
167 167
      */
168 168
     public function match(UriInterface $uri, array $defaults): ?array
169 169
     {
170
-        if (!$this->isCompiled()) {
170
+        if (!$this->isCompiled()){
171 171
             $this->compile();
172 172
         }
173 173
 
174 174
         $matches = [];
175
-        if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)) {
175
+        if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)){
176 176
             return null;
177 177
         }
178 178
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      */
191 191
     public function uri($parameters = [], array $defaults = []): UriInterface
192 192
     {
193
-        if (!$this->isCompiled()) {
193
+        if (!$this->isCompiled()){
194 194
             $this->compile();
195 195
         }
196 196
 
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
             $this->fetchOptions($parameters, $query)
201 201
         );
202 202
 
203
-        foreach ($this->constrains as $key => $values) {
204
-            if (empty($parameters[$key])) {
203
+        foreach ($this->constrains as $key => $values){
204
+            if (empty($parameters[$key])){
205 205
                 throw new UriHandlerException("Unable to generate Uri, parameter `{$key}` is missing");
206 206
             }
207 207
         }
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         $path = $this->interpolate($this->template, $parameters);
211 211
 
212 212
         //Uri with added prefix
213
-        $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->prefix) . trim($path, '/'));
213
+        $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->prefix).trim($path, '/'));
214 214
 
215 215
         return empty($query) ? $uri : $uri->withQuery(http_build_query($query));
216 216
     }
@@ -227,18 +227,18 @@  discard block
 block discarded – undo
227 227
         $allowed = array_keys($this->options);
228 228
 
229 229
         $result = [];
230
-        foreach ($parameters as $key => $parameter) {
231
-            if (is_numeric($key) && isset($allowed[$key])) {
230
+        foreach ($parameters as $key => $parameter){
231
+            if (is_numeric($key) && isset($allowed[$key])){
232 232
                 // this segment fetched keys from given parameters either by name or by position
233 233
                 $key = $allowed[$key];
234
-            } elseif (!array_key_exists($key, $this->options) && is_array($parameters)) {
234
+            } elseif (!array_key_exists($key, $this->options) && is_array($parameters)){
235 235
                 // all additional parameters given in array form can be glued to query string
236 236
                 $query[$key] = $parameter;
237 237
                 continue;
238 238
             }
239 239
 
240 240
             //String must be normalized here
241
-            if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)) {
241
+            if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)){
242 242
                 $result[$key] = $this->slugify->slugify($parameter);
243 243
                 continue;
244 244
             }
@@ -259,15 +259,15 @@  discard block
 block discarded – undo
259 259
     {
260 260
         $path = $uri->getPath();
261 261
 
262
-        if (empty($path) || $path[0] !== '/') {
263
-            $path = '/' . $path;
262
+        if (empty($path) || $path[0] !== '/'){
263
+            $path = '/'.$path;
264 264
         }
265 265
 
266
-        if ($this->matchHost) {
267
-            $uriString = $uri->getHost() . $path;
268
-        } else {
266
+        if ($this->matchHost){
267
+            $uriString = $uri->getHost().$path;
268
+        }else{
269 269
             $uriString = substr($path, strlen($this->prefix));
270
-            if ($uriString === false) {
270
+            if ($uriString === false){
271 271
                 $uriString = '';
272 272
             }
273 273
         }
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
      */
281 281
     private function compile(): void
282 282
     {
283
-        if ($this->pattern === null) {
283
+        if ($this->pattern === null){
284 284
             throw new UriHandlerException('Unable to compile UriHandler, pattern is not set');
285 285
         }
286 286
 
@@ -288,14 +288,14 @@  discard block
 block discarded – undo
288 288
         $pattern = rtrim(ltrim($this->pattern, ':/'), '/');
289 289
 
290 290
         // correct [/ first occurrence]
291
-        if (strpos($pattern, '[/') === 0) {
292
-            $pattern = '[' . substr($pattern, 2);
291
+        if (strpos($pattern, '[/') === 0){
292
+            $pattern = '['.substr($pattern, 2);
293 293
         }
294 294
 
295
-        if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) {
295
+        if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)){
296 296
             $variables = array_combine($matches[1], $matches[2]);
297 297
 
298
-            foreach ($variables as $key => $segment) {
298
+            foreach ($variables as $key => $segment){
299 299
                 $segment = $this->prepareSegment($key, $segment);
300 300
                 $replaces["<$key>"] = "(?P<$key>$segment)";
301 301
                 $options[] = $key;
@@ -305,13 +305,13 @@  discard block
 block discarded – undo
305 305
         $template = preg_replace('/<(\w+):?.*?>/', '<\1>', $pattern);
306 306
         $options = array_fill_keys($options, null);
307 307
 
308
-        foreach ($this->constrains as $key => $value) {
309
-            if ($value instanceof Autofill) {
308
+        foreach ($this->constrains as $key => $value){
309
+            if ($value instanceof Autofill){
310 310
                 // only forces value replacement, not required to be presented as parameter
311 311
                 continue;
312 312
             }
313 313
 
314
-            if (!array_key_exists($key, $options) && !isset($this->defaults[$key])) {
314
+            if (!array_key_exists($key, $options) && !isset($this->defaults[$key])){
315 315
                 throw new ConstrainException(
316 316
                     sprintf(
317 317
                         'Route `%s` does not define routing parameter `<%s>`.',
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
             }
323 323
         }
324 324
 
325
-        $this->compiled = '/^' . strtr($template, $replaces + self::PATTERN_REPLACES) . '$/iu';
325
+        $this->compiled = '/^'.strtr($template, $replaces + self::PATTERN_REPLACES).'$/iu';
326 326
         $this->template = stripslashes(str_replace('?', '', $template));
327 327
         $this->options = $options;
328 328
     }
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
     private function interpolate(string $string, array $values): string
338 338
     {
339 339
         $replaces = [];
340
-        foreach ($values as $key => $value) {
340
+        foreach ($values as $key => $value){
341 341
             $value = (is_array($value) || $value instanceof \Closure) ? '' : $value;
342 342
             $replaces["<{$key}>"] = is_object($value) ? (string)$value : $value;
343 343
         }
@@ -354,15 +354,15 @@  discard block
 block discarded – undo
354 354
      */
355 355
     private function prepareSegment(string $name, string $segment): string
356 356
     {
357
-        if ($segment !== '') {
357
+        if ($segment !== ''){
358 358
             return self::SEGMENT_TYPES[$segment] ?? $segment;
359 359
         }
360 360
 
361
-        if (!isset($this->constrains[$name])) {
361
+        if (!isset($this->constrains[$name])){
362 362
             return self::DEFAULT_SEGMENT;
363 363
         }
364 364
 
365
-        if (is_array($this->constrains[$name])) {
365
+        if (is_array($this->constrains[$name])){
366 366
             $values = array_map([$this, 'filterSegment'], $this->constrains[$name]);
367 367
 
368 368
             return implode('|', $values);
Please login to merge, or discard this patch.
Braces   +50 added lines, -24 removed lines patch added patch discarded remove patch
@@ -167,12 +167,14 @@  discard block
 block discarded – undo
167 167
      */
168 168
     public function match(UriInterface $uri, array $defaults): ?array
169 169
     {
170
-        if (!$this->isCompiled()) {
170
+        if (!$this->isCompiled())
171
+        {
171 172
             $this->compile();
172 173
         }
173 174
 
174 175
         $matches = [];
175
-        if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches)) {
176
+        if (!preg_match($this->compiled, $this->fetchTarget($uri), $matches))
177
+        {
176 178
             return null;
177 179
         }
178 180
 
@@ -190,7 +192,8 @@  discard block
 block discarded – undo
190 192
      */
191 193
     public function uri($parameters = [], array $defaults = []): UriInterface
192 194
     {
193
-        if (!$this->isCompiled()) {
195
+        if (!$this->isCompiled())
196
+        {
194 197
             $this->compile();
195 198
         }
196 199
 
@@ -200,8 +203,10 @@  discard block
 block discarded – undo
200 203
             $this->fetchOptions($parameters, $query)
201 204
         );
202 205
 
203
-        foreach ($this->constrains as $key => $values) {
204
-            if (empty($parameters[$key])) {
206
+        foreach ($this->constrains as $key => $values)
207
+        {
208
+            if (empty($parameters[$key]))
209
+            {
205 210
                 throw new UriHandlerException("Unable to generate Uri, parameter `{$key}` is missing");
206 211
             }
207 212
         }
@@ -227,18 +232,23 @@  discard block
 block discarded – undo
227 232
         $allowed = array_keys($this->options);
228 233
 
229 234
         $result = [];
230
-        foreach ($parameters as $key => $parameter) {
231
-            if (is_numeric($key) && isset($allowed[$key])) {
235
+        foreach ($parameters as $key => $parameter)
236
+        {
237
+            if (is_numeric($key) && isset($allowed[$key]))
238
+            {
232 239
                 // this segment fetched keys from given parameters either by name or by position
233 240
                 $key = $allowed[$key];
234
-            } elseif (!array_key_exists($key, $this->options) && is_array($parameters)) {
241
+            }
242
+            elseif (!array_key_exists($key, $this->options) && is_array($parameters))
243
+            {
235 244
                 // all additional parameters given in array form can be glued to query string
236 245
                 $query[$key] = $parameter;
237 246
                 continue;
238 247
             }
239 248
 
240 249
             //String must be normalized here
241
-            if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter)) {
250
+            if (is_string($parameter) && !preg_match('/^[a-z\-_0-9]+$/i', $parameter))
251
+            {
242 252
                 $result[$key] = $this->slugify->slugify($parameter);
243 253
                 continue;
244 254
             }
@@ -259,15 +269,20 @@  discard block
 block discarded – undo
259 269
     {
260 270
         $path = $uri->getPath();
261 271
 
262
-        if (empty($path) || $path[0] !== '/') {
272
+        if (empty($path) || $path[0] !== '/')
273
+        {
263 274
             $path = '/' . $path;
264 275
         }
265 276
 
266
-        if ($this->matchHost) {
277
+        if ($this->matchHost)
278
+        {
267 279
             $uriString = $uri->getHost() . $path;
268
-        } else {
280
+        }
281
+        else
282
+        {
269 283
             $uriString = substr($path, strlen($this->prefix));
270
-            if ($uriString === false) {
284
+            if ($uriString === false)
285
+            {
271 286
                 $uriString = '';
272 287
             }
273 288
         }
@@ -280,7 +295,8 @@  discard block
 block discarded – undo
280 295
      */
281 296
     private function compile(): void
282 297
     {
283
-        if ($this->pattern === null) {
298
+        if ($this->pattern === null)
299
+        {
284 300
             throw new UriHandlerException('Unable to compile UriHandler, pattern is not set');
285 301
         }
286 302
 
@@ -288,14 +304,17 @@  discard block
 block discarded – undo
288 304
         $pattern = rtrim(ltrim($this->pattern, ':/'), '/');
289 305
 
290 306
         // correct [/ first occurrence]
291
-        if (strpos($pattern, '[/') === 0) {
307
+        if (strpos($pattern, '[/') === 0)
308
+        {
292 309
             $pattern = '[' . substr($pattern, 2);
293 310
         }
294 311
 
295
-        if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) {
312
+        if (preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches))
313
+        {
296 314
             $variables = array_combine($matches[1], $matches[2]);
297 315
 
298
-            foreach ($variables as $key => $segment) {
316
+            foreach ($variables as $key => $segment)
317
+            {
299 318
                 $segment = $this->prepareSegment($key, $segment);
300 319
                 $replaces["<$key>"] = "(?P<$key>$segment)";
301 320
                 $options[] = $key;
@@ -305,13 +324,16 @@  discard block
 block discarded – undo
305 324
         $template = preg_replace('/<(\w+):?.*?>/', '<\1>', $pattern);
306 325
         $options = array_fill_keys($options, null);
307 326
 
308
-        foreach ($this->constrains as $key => $value) {
309
-            if ($value instanceof Autofill) {
327
+        foreach ($this->constrains as $key => $value)
328
+        {
329
+            if ($value instanceof Autofill)
330
+            {
310 331
                 // only forces value replacement, not required to be presented as parameter
311 332
                 continue;
312 333
             }
313 334
 
314
-            if (!array_key_exists($key, $options) && !isset($this->defaults[$key])) {
335
+            if (!array_key_exists($key, $options) && !isset($this->defaults[$key]))
336
+            {
315 337
                 throw new ConstrainException(
316 338
                     sprintf(
317 339
                         'Route `%s` does not define routing parameter `<%s>`.',
@@ -337,7 +359,8 @@  discard block
 block discarded – undo
337 359
     private function interpolate(string $string, array $values): string
338 360
     {
339 361
         $replaces = [];
340
-        foreach ($values as $key => $value) {
362
+        foreach ($values as $key => $value)
363
+        {
341 364
             $value = (is_array($value) || $value instanceof \Closure) ? '' : $value;
342 365
             $replaces["<{$key}>"] = is_object($value) ? (string)$value : $value;
343 366
         }
@@ -354,15 +377,18 @@  discard block
 block discarded – undo
354 377
      */
355 378
     private function prepareSegment(string $name, string $segment): string
356 379
     {
357
-        if ($segment !== '') {
380
+        if ($segment !== '')
381
+        {
358 382
             return self::SEGMENT_TYPES[$segment] ?? $segment;
359 383
         }
360 384
 
361
-        if (!isset($this->constrains[$name])) {
385
+        if (!isset($this->constrains[$name]))
386
+        {
362 387
             return self::DEFAULT_SEGMENT;
363 388
         }
364 389
 
365
-        if (is_array($this->constrains[$name])) {
390
+        if (is_array($this->constrains[$name]))
391
+        {
366 392
             $values = array_map([$this, 'filterSegment'], $this->constrains[$name]);
367 393
 
368 394
             return implode('|', $values);
Please login to merge, or discard this patch.
src/Session/tests/FactoryTest.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 {
25 25
     public function tearDown(): void
26 26
     {
27
-        if ((int)session_status() === PHP_SESSION_ACTIVE) {
27
+        if ((int)session_status() === PHP_SESSION_ACTIVE){
28 28
             session_abort();
29 29
         }
30 30
     }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,8 @@
 block discarded – undo
24 24
 {
25 25
     public function tearDown(): void
26 26
     {
27
-        if ((int)session_status() === PHP_SESSION_ACTIVE) {
27
+        if ((int)session_status() === PHP_SESSION_ACTIVE)
28
+        {
28 29
             session_abort();
29 30
         }
30 31
     }
Please login to merge, or discard this patch.
src/Session/tests/SessionTest.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
     public function tearDown(): void
53 53
     {
54
-        if ((int)session_status() === PHP_SESSION_ACTIVE) {
54
+        if ((int)session_status() === PHP_SESSION_ACTIVE){
55 55
             session_abort();
56 56
         }
57 57
     }
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
         $this->assertSame('default', $section->getName());
126 126
 
127 127
         $section->set('key', 'value');
128
-        foreach ($section as $key => $value) {
128
+        foreach ($section as $key => $value){
129 129
             $this->assertSame('key', $key);
130 130
             $this->assertSame('value', $value);
131 131
         }
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,8 @@  discard block
 block discarded – undo
51 51
 
52 52
     public function tearDown(): void
53 53
     {
54
-        if ((int)session_status() === PHP_SESSION_ACTIVE) {
54
+        if ((int)session_status() === PHP_SESSION_ACTIVE)
55
+        {
55 56
             session_abort();
56 57
         }
57 58
     }
@@ -125,7 +126,8 @@  discard block
 block discarded – undo
125 126
         $this->assertSame('default', $section->getName());
126 127
 
127 128
         $section->set('key', 'value');
128
-        foreach ($section as $key => $value) {
129
+        foreach ($section as $key => $value)
130
+        {
129 131
             $this->assertSame('key', $key);
130 132
             $this->assertSame('value', $value);
131 133
         }
Please login to merge, or discard this patch.
src/Session/src/SessionSection.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function get(string $name, $default = null)
129 129
     {
130
-        if (!$this->has($name)) {
130
+        if (!$this->has($name)){
131 131
             return $default;
132 132
         }
133 133
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     {
203 203
         $this->session->resume();
204 204
 
205
-        if (!isset($_SESSION[$this->name])) {
205
+        if (!isset($_SESSION[$this->name])){
206 206
             $_SESSION[$this->name] = [];
207 207
         }
208 208
     }
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -127,7 +127,8 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function get(string $name, $default = null)
129 129
     {
130
-        if (!$this->has($name)) {
130
+        if (!$this->has($name))
131
+        {
131 132
             return $default;
132 133
         }
133 134
 
@@ -202,7 +203,8 @@  discard block
 block discarded – undo
202 203
     {
203 204
         $this->session->resume();
204 205
 
205
-        if (!isset($_SESSION[$this->name])) {
206
+        if (!isset($_SESSION[$this->name]))
207
+        {
206 208
             $_SESSION[$this->name] = [];
207 209
         }
208 210
     }
Please login to merge, or discard this patch.
src/Session/src/Handler/FileHandler.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,8 +62,8 @@
 block discarded – undo
62 62
      */
63 63
     public function gc($maxlifetime): void
64 64
     {
65
-        foreach ($this->files->getFiles($this->directory) as $filename) {
66
-            if ($this->files->time($filename) < time() - $maxlifetime) {
65
+        foreach ($this->files->getFiles($this->directory) as $filename){
66
+            if ($this->files->time($filename) < time() - $maxlifetime){
67 67
                 $this->files->delete($filename);
68 68
             }
69 69
         }
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,8 +62,10 @@
 block discarded – undo
62 62
      */
63 63
     public function gc($maxlifetime): void
64 64
     {
65
-        foreach ($this->files->getFiles($this->directory) as $filename) {
66
-            if ($this->files->time($filename) < time() - $maxlifetime) {
65
+        foreach ($this->files->getFiles($this->directory) as $filename)
66
+        {
67
+            if ($this->files->time($filename) < time() - $maxlifetime)
68
+            {
67 69
                 $this->files->delete($filename);
68 70
             }
69 71
         }
Please login to merge, or discard this patch.
src/Session/src/SessionFactory.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -48,15 +48,15 @@
 block discarded – undo
48 48
      */
49 49
     public function initSession(string $clientSignature, string $id = null): SessionInterface
50 50
     {
51
-        if ((int)session_status() === PHP_SESSION_ACTIVE) {
51
+        if ((int)session_status() === PHP_SESSION_ACTIVE){
52 52
             throw new MultipleSessionException('Unable to initiate session, session already started');
53 53
         }
54 54
 
55 55
         //Initiating proper session handler
56
-        if ($this->config->getHandler() !== null) {
57
-            try {
56
+        if ($this->config->getHandler() !== null){
57
+            try{
58 58
                 $handler = $this->config->getHandler()->resolve($this->factory);
59
-            } catch (\Throwable | ContainerExceptionInterface $e) {
59
+            }catch (\Throwable | ContainerExceptionInterface $e){
60 60
                 throw new SessionException($e->getMessage(), $e->getCode(), $e);
61 61
             }
62 62
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -48,15 +48,20 @@
 block discarded – undo
48 48
      */
49 49
     public function initSession(string $clientSignature, string $id = null): SessionInterface
50 50
     {
51
-        if ((int)session_status() === PHP_SESSION_ACTIVE) {
51
+        if ((int)session_status() === PHP_SESSION_ACTIVE)
52
+        {
52 53
             throw new MultipleSessionException('Unable to initiate session, session already started');
53 54
         }
54 55
 
55 56
         //Initiating proper session handler
56
-        if ($this->config->getHandler() !== null) {
57
-            try {
57
+        if ($this->config->getHandler() !== null)
58
+        {
59
+            try
60
+            {
58 61
                 $handler = $this->config->getHandler()->resolve($this->factory);
59
-            } catch (\Throwable | ContainerExceptionInterface $e) {
62
+            }
63
+            catch (\Throwable | ContainerExceptionInterface $e)
64
+            {
60 65
                 throw new SessionException($e->getMessage(), $e->getCode(), $e);
61 66
             }
62 67
 
Please login to merge, or discard this patch.
src/Session/src/Session.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         $this->clientSignature = $clientSignature;
73 73
         $this->lifetime = $lifetime;
74 74
 
75
-        if (!empty($id) && $this->validID($id)) {
75
+        if (!empty($id) && $this->validID($id)){
76 76
             $this->id = $id;
77 77
         }
78 78
     }
@@ -103,24 +103,24 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function resume(): void
105 105
     {
106
-        if ($this->isStarted()) {
106
+        if ($this->isStarted()){
107 107
             return;
108 108
         }
109 109
 
110
-        if (!empty($this->id)) {
110
+        if (!empty($this->id)){
111 111
             session_id($this->id);
112
-        } else {
112
+        }else{
113 113
             // always new id
114 114
             session_id(session_create_id());
115 115
         }
116 116
 
117
-        try {
117
+        try{
118 118
             session_start(['use_cookies' => false]);
119
-        } catch (\Throwable $e) {
119
+        }catch (\Throwable $e){
120 120
             throw new SessionException('Unable to start session', $e->getCode(), $e);
121 121
         }
122 122
 
123
-        if (empty($this->id)) {
123
+        if (empty($this->id)){
124 124
             //Sign newly created session
125 125
             $_SESSION[self::CLIENT_SIGNATURE] = $this->clientSignature;
126 126
             $_SESSION[self::SESSION_CREATED] = time();
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
         $this->started = true;
132 132
 
133 133
         //Ensure that session is valid
134
-        if (!$this->validSession()) {
134
+        if (!$this->validSession()){
135 135
             $this->invalidateSession();
136 136
         }
137 137
     }
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      */
171 171
     public function commit(): bool
172 172
     {
173
-        if (!$this->isStarted()) {
173
+        if (!$this->isStarted()){
174 174
             return false;
175 175
         }
176 176
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      */
186 186
     public function abort(): bool
187 187
     {
188
-        if (!$this->isStarted()) {
188
+        if (!$this->isStarted()){
189 189
             return false;
190 190
         }
191 191
 
@@ -228,17 +228,17 @@  discard block
 block discarded – undo
228 228
         if (
229 229
             !array_key_exists(self::CLIENT_SIGNATURE, $_SESSION)
230 230
             || !array_key_exists(self::SESSION_CREATED, $_SESSION)
231
-        ) {
231
+        ){
232 232
             //Missing session signature or timestamp!
233 233
             return false;
234 234
         }
235 235
 
236
-        if ($_SESSION[self::SESSION_CREATED] < time() - $this->lifetime) {
236
+        if ($_SESSION[self::SESSION_CREATED] < time() - $this->lifetime){
237 237
             //Session expired
238 238
             return false;
239 239
         }
240 240
 
241
-        if (!hash_equals($_SESSION[self::CLIENT_SIGNATURE], $this->clientSignature)) {
241
+        if (!hash_equals($_SESSION[self::CLIENT_SIGNATURE], $this->clientSignature)){
242 242
             //Signatures do not match
243 243
             return false;
244 244
         }
Please login to merge, or discard this patch.
Braces   +26 added lines, -12 removed lines patch added patch discarded remove patch
@@ -72,7 +72,8 @@  discard block
 block discarded – undo
72 72
         $this->clientSignature = $clientSignature;
73 73
         $this->lifetime = $lifetime;
74 74
 
75
-        if (!empty($id) && $this->validID($id)) {
75
+        if (!empty($id) && $this->validID($id))
76
+        {
76 77
             $this->id = $id;
77 78
         }
78 79
     }
@@ -103,24 +104,32 @@  discard block
 block discarded – undo
103 104
      */
104 105
     public function resume(): void
105 106
     {
106
-        if ($this->isStarted()) {
107
+        if ($this->isStarted())
108
+        {
107 109
             return;
108 110
         }
109 111
 
110
-        if (!empty($this->id)) {
112
+        if (!empty($this->id))
113
+        {
111 114
             session_id($this->id);
112
-        } else {
115
+        }
116
+        else
117
+        {
113 118
             // always new id
114 119
             session_id(session_create_id());
115 120
         }
116 121
 
117
-        try {
122
+        try
123
+        {
118 124
             session_start(['use_cookies' => false]);
119
-        } catch (\Throwable $e) {
125
+        }
126
+        catch (\Throwable $e)
127
+        {
120 128
             throw new SessionException('Unable to start session', $e->getCode(), $e);
121 129
         }
122 130
 
123
-        if (empty($this->id)) {
131
+        if (empty($this->id))
132
+        {
124 133
             //Sign newly created session
125 134
             $_SESSION[self::CLIENT_SIGNATURE] = $this->clientSignature;
126 135
             $_SESSION[self::SESSION_CREATED] = time();
@@ -131,7 +140,8 @@  discard block
 block discarded – undo
131 140
         $this->started = true;
132 141
 
133 142
         //Ensure that session is valid
134
-        if (!$this->validSession()) {
143
+        if (!$this->validSession())
144
+        {
135 145
             $this->invalidateSession();
136 146
         }
137 147
     }
@@ -170,7 +180,8 @@  discard block
 block discarded – undo
170 180
      */
171 181
     public function commit(): bool
172 182
     {
173
-        if (!$this->isStarted()) {
183
+        if (!$this->isStarted())
184
+        {
174 185
             return false;
175 186
         }
176 187
 
@@ -185,7 +196,8 @@  discard block
 block discarded – undo
185 196
      */
186 197
     public function abort(): bool
187 198
     {
188
-        if (!$this->isStarted()) {
199
+        if (!$this->isStarted())
200
+        {
189 201
             return false;
190 202
         }
191 203
 
@@ -233,12 +245,14 @@  discard block
 block discarded – undo
233 245
             return false;
234 246
         }
235 247
 
236
-        if ($_SESSION[self::SESSION_CREATED] < time() - $this->lifetime) {
248
+        if ($_SESSION[self::SESSION_CREATED] < time() - $this->lifetime)
249
+        {
237 250
             //Session expired
238 251
             return false;
239 252
         }
240 253
 
241
-        if (!hash_equals($_SESSION[self::CLIENT_SIGNATURE], $this->clientSignature)) {
254
+        if (!hash_equals($_SESSION[self::CLIENT_SIGNATURE], $this->clientSignature))
255
+        {
242 256
             //Signatures do not match
243 257
             return false;
244 258
         }
Please login to merge, or discard this patch.