Test Failed
Pull Request — master (#1192)
by butschster
10:57
created
src/Router/tests/UriTest.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 
107 107
         $uri = $router->uri('test:id', [
108 108
             'id' => 100,
109
-            'title' => new class implements \Stringable {
109
+            'title' => new class implements \Stringable{
110 110
                 public function __toString()
111 111
                 {
112 112
                     return 'hello-world';
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
         $uriHandler->setStrict(true);
202 202
         $route = $route->withUriHandler($uriHandler);
203 203
 
204
-        self::assertSame($expected, (string) $route->uri($params));
204
+        self::assertSame($expected, (string)$route->uri($params));
205 205
     }
206 206
 
207 207
     #[DataProvider('provideSegmentInDifferentLanguages')]
Please login to merge, or discard this patch.
src/Router/src/UriHandler.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         private readonly UriFactoryInterface $uriFactory,
61 61
         ?SlugifyInterface $slugify = null,
62 62
         ?RoutePatternRegistryInterface $patternRegistry = null,
63
-    ) {
63
+    ){
64 64
         $this->patternRegistry = $patternRegistry ?? new DefaultPatternRegistry();
65 65
 
66 66
         $slugify ??= new Slugify();
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      */
131 131
     public function withBasePath(string $basePath): self
132 132
     {
133
-        if (!\str_ends_with($basePath, '/')) {
133
+        if (!\str_ends_with($basePath, '/')){
134 134
             $basePath .= '/';
135 135
         }
136 136
 
@@ -180,12 +180,12 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function match(UriInterface $uri, array $defaults): ?array
182 182
     {
183
-        if (!$this->isCompiled()) {
183
+        if (!$this->isCompiled()){
184 184
             $this->compile();
185 185
         }
186 186
 
187 187
         $matches = [];
188
-        if (!\preg_match($this->compiled, $this->fetchTarget($uri), $matches)) {
188
+        if (!\preg_match($this->compiled, $this->fetchTarget($uri), $matches)){
189 189
             return null;
190 190
         }
191 191
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
      */
203 203
     public function uri(iterable $parameters = [], array $defaults = []): UriInterface
204 204
     {
205
-        if (!$this->isCompiled()) {
205
+        if (!$this->isCompiled()){
206 206
             $this->compile();
207 207
         }
208 208
 
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
 
215 215
         $required = \array_keys($this->constrains);
216 216
         $parametersToCheck = $parameters;
217
-        if ($this->strict) {
217
+        if ($this->strict){
218 218
             $required = \array_unique([...$this->requiredOptions, ...$required]);
219 219
             $parametersToCheck = \array_filter($parametersToCheck);
220 220
         }
221 221
 
222 222
         $missingParameters = \array_diff($required, \array_keys($parametersToCheck));
223
-        if ($missingParameters !== []) {
223
+        if ($missingParameters !== []){
224 224
             throw new UriHandlerException(
225 225
                 \sprintf(
226 226
                     \count($missingParameters) === 1
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         $path = $this->interpolate($this->template, $parameters);
236 236
 
237 237
         //Uri with added base path and prefix
238
-        $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->basePath) . \trim($path, '/'));
238
+        $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->basePath).\trim($path, '/'));
239 239
 
240 240
         return empty($query) ? $uri : $uri->withQuery(\http_build_query($query));
241 241
     }
@@ -250,23 +250,23 @@  discard block
 block discarded – undo
250 250
         $allowed = \array_keys($this->options);
251 251
 
252 252
         $result = [];
253
-        foreach ($parameters as $key => $parameter) {
254
-            if (\is_int($key) && isset($allowed[$key])) {
253
+        foreach ($parameters as $key => $parameter){
254
+            if (\is_int($key) && isset($allowed[$key])){
255 255
                 // this segment fetched keys from given parameters either by name or by position
256 256
                 $key = $allowed[$key];
257
-            } elseif (!\array_key_exists($key, $this->options) && \is_array($parameters)) {
257
+            } elseif (!\array_key_exists($key, $this->options) && \is_array($parameters)){
258 258
                 // all additional parameters given in array form can be glued to query string
259 259
                 $query[$key] = $parameter;
260 260
                 continue;
261 261
             }
262 262
 
263 263
             // String must be normalized here
264
-            if (\is_string($parameter) && !\preg_match('/^[a-z\-_0-9]+$/i', $parameter)) {
264
+            if (\is_string($parameter) && !\preg_match('/^[a-z\-_0-9]+$/i', $parameter)){
265 265
                 $result[$key] = ($this->pathSegmentEncoder)($parameter);
266 266
                 continue;
267 267
             }
268 268
 
269
-            $result[$key] = (string) $parameter;
269
+            $result[$key] = (string)$parameter;
270 270
         }
271 271
 
272 272
         return $result;
@@ -279,13 +279,13 @@  discard block
 block discarded – undo
279 279
     {
280 280
         $path = $uri->getPath();
281 281
 
282
-        if (empty($path) || $path[0] !== '/') {
283
-            $path = '/' . $path;
282
+        if (empty($path) || $path[0] !== '/'){
283
+            $path = '/'.$path;
284 284
         }
285 285
 
286
-        if ($this->matchHost) {
287
-            $uriString = $uri->getHost() . $path;
288
-        } else {
286
+        if ($this->matchHost){
287
+            $uriString = $uri->getHost().$path;
288
+        }else{
289 289
             $uriString = \substr($path, \strlen($this->basePath)) ?: '';
290 290
         }
291 291
 
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
      */
301 301
     private function compile(): void
302 302
     {
303
-        if ($this->pattern === null) {
303
+        if ($this->pattern === null){
304 304
             throw new UriHandlerException('Unable to compile UriHandler, pattern is not set');
305 305
         }
306 306
 
@@ -310,19 +310,19 @@  discard block
 block discarded – undo
310 310
         // 1) Build full pattern
311 311
         $prefix = \rtrim($this->getPrefix(), '/ ');
312 312
         $pattern = \ltrim($this->pattern, '/ ');
313
-        $pattern = $prefix . '/' . $pattern;
313
+        $pattern = $prefix.'/'.$pattern;
314 314
         $pattern = \rtrim(\ltrim($pattern, ':/'), '/');
315 315
 
316 316
         // correct [/ first occurrence]
317
-        if (\str_starts_with($pattern, '[/')) {
318
-            $pattern = '[' . \substr($pattern, 2);
317
+        if (\str_starts_with($pattern, '[/')){
318
+            $pattern = '['.\substr($pattern, 2);
319 319
         }
320 320
 
321 321
         // 2) Extract variables from the pattern
322
-        if (\preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) {
322
+        if (\preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)){
323 323
             $variables = \array_combine($matches[1], $matches[2]);
324 324
 
325
-            foreach ($variables as $key => $segment) {
325
+            foreach ($variables as $key => $segment){
326 326
                 $segment = $this->prepareSegment($key, $segment);
327 327
                 $replaces[\sprintf('<%s>', $key)] = \sprintf('(?P<%s>%s)', $key, $segment);
328 328
                 $options[] = $key;
@@ -334,14 +334,14 @@  discard block
 block discarded – undo
334 334
         $options = \array_fill_keys($options, null);
335 335
 
336 336
         // 3) Validate constraints
337
-        foreach ($this->constrains as $key => $value) {
338
-            if ($value instanceof Autofill) {
337
+        foreach ($this->constrains as $key => $value){
338
+            if ($value instanceof Autofill){
339 339
                 // only forces value replacement, not required to be presented as parameter
340 340
                 continue;
341 341
             }
342 342
 
343 343
             // If a constraint references a param that doesn't appear in the pattern or defaults
344
-            if (!\array_key_exists($key, $options) && !isset($this->defaults[$key])) {
344
+            if (!\array_key_exists($key, $options) && !isset($this->defaults[$key])){
345 345
                 throw new ConstrainException(
346 346
                     \sprintf(
347 347
                         'Route `%s` does not define routing parameter `<%s>`.',
@@ -353,12 +353,12 @@  discard block
 block discarded – undo
353 353
         }
354 354
 
355 355
         // 4) Compile your final regex pattern
356
-        $this->compiled = '/^' . \strtr($template, $replaces + self::PATTERN_REPLACES) . '$/iu';
356
+        $this->compiled = '/^'.\strtr($template, $replaces + self::PATTERN_REPLACES).'$/iu';
357 357
         $this->template = \stripslashes(\str_replace('?', '', $template));
358 358
         $this->options = $options;
359 359
 
360 360
         // 5) Mark which parameters are required vs. optional
361
-        if ($this->strict) {
361
+        if ($this->strict){
362 362
             $this->requiredOptions = $this->findRequiredOptions($pattern, \array_keys($options));
363 363
         }
364 364
     }
@@ -380,20 +380,20 @@  discard block
 block discarded – undo
380 380
         $pos = 0;
381 381
         $length = \strlen($pattern);
382 382
 
383
-        while ($pos < $length) {
383
+        while ($pos < $length){
384 384
             $char = $pattern[$pos];
385 385
 
386 386
             // We enter an optional segment
387
-            if ($char === '[') {
387
+            if ($char === '['){
388 388
                 \array_push($stack, '[');
389 389
             } // We exit an optional segment
390
-            elseif ($char === ']') {
390
+            elseif ($char === ']'){
391 391
                 \array_pop($stack);
392 392
             } // We see a parameter like <id> or <action:\d+>
393
-            elseif ($char === '<') {
393
+            elseif ($char === '<'){
394 394
                 // Find the closing '>'
395 395
                 $endPos = \strpos($pattern, '>', $pos);
396
-                if ($endPos === false) {
396
+                if ($endPos === false){
397 397
                     break;
398 398
                 }
399 399
 
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
                 $varName = \explode(':', $varPart)[0];
405 405
 
406 406
                 // If we are inside a bracket, that var is optional
407
-                if ($stack !== []) {
407
+                if ($stack !== []){
408 408
                     $optionalVars[] = $varName;
409 409
                 }
410 410
 
@@ -429,9 +429,9 @@  discard block
 block discarded – undo
429 429
     private function interpolate(string $string, array $values): string
430 430
     {
431 431
         $replaces = [];
432
-        foreach ($values as $key => $value) {
432
+        foreach ($values as $key => $value){
433 433
             $replaces[\sprintf('<%s>', $key)] = match (true) {
434
-                $value instanceof \Stringable || \is_scalar($value) => (string) $value,
434
+                $value instanceof \Stringable || \is_scalar($value) => (string)$value,
435 435
                 default => '',
436 436
             };
437 437
         }
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
                 '|',
452 452
                 \array_map(fn(string $segment): string => $this->filterSegment($segment), $this->constrains[$name]),
453 453
             ),
454
-            default => $this->filterSegment((string) $this->constrains[$name])
454
+            default => $this->filterSegment((string)$this->constrains[$name])
455 455
         };
456 456
     }
457 457
 
Please login to merge, or discard this patch.