Passed
Push — refactor ( 834b7c...6a891c )
by Florian
01:56
created
src/Router.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
     public function setBasePath(string $basePath): self
184 184
     {
185 185
         $basePath = trim($basePath, '/');
186
-        $this->basePath = $basePath ? '/' . $basePath : '';
186
+        $this->basePath = $basePath ? '/'.$basePath : '';
187 187
         return $this;
188 188
     }
189 189
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
             $options['host'] = $this->hosts[$scheme][$host];
221 221
         }
222 222
 
223
-        $patternKey = md5($options['pattern'] . '-' . $options['name']);
223
+        $patternKey = md5($options['pattern'].'-'.$options['name']);
224 224
         if (isset($this->pattern[$scheme][$host][$patternKey])) {
225 225
             $route = $this->pattern[$scheme][$host][$patternKey];
226 226
         } else {
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
             $options['host'] = $this->hosts[$scheme][$host];
281 281
         }
282 282
 
283
-        $patternKey = md5($options['pattern'] . '-' . $options['name']);
283
+        $patternKey = md5($options['pattern'].'-'.$options['name']);
284 284
         if (isset($this->pattern[$scheme][$host][$patternKey])) {
285 285
             $instance = $this->pattern[$scheme][$host][$patternKey];
286 286
         } else {
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
             $this->pattern[$scheme][$host][$patternKey] = $instance;
294 294
         }
295 295
 
296
-        $methods = $options['methods'] ? (array)$options['methods'] : [];
296
+        $methods = $options['methods'] ? (array) $options['methods'] : [];
297 297
         $instance->allow($methods);
298 298
         foreach ($methods as $method) {
299 299
             $this->routes[$scheme][$host][strtoupper($method)][] = $instance;
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
             $request = $parsed + $request;
412 412
         }
413 413
 
414
-        $request['path'] = (ltrim((string)strtok($request['path'], '?'), '/'));
414
+        $request['path'] = (ltrim((string) strtok($request['path'], '?'), '/'));
415 415
         $request['method'] = strtoupper($request['method']);
416 416
 
417 417
         return $request;
Please login to merge, or discard this patch.
spec/Suite/Router.spec.php 1 patch
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -12,32 +12,32 @@  discard block
 block discarded – undo
12 12
 use Psr\Http\Message\ServerRequestInterface;
13 13
 use Psr\Http\Message\UriInterface;
14 14
 
15
-describe("Router", function () {
15
+describe("Router", function() {
16 16
 
17 17
 
18
-    beforeEach(function () {
18
+    beforeEach(function() {
19 19
 
20 20
 
21 21
         $this->router = new Router();
22
-        $this->export = function ($request) {
22
+        $this->export = function($request) {
23 23
 
24 24
             return array_intersect_key($request, array_fill_keys(['path', 'method', 'host', 'scheme'], true));
25 25
         };
26 26
     });
27
-    describe("->__construct()", function () {
27
+    describe("->__construct()", function() {
28 28
 
29 29
 
30
-        it("formats the basePath", function () {
30
+        it("formats the basePath", function() {
31 31
 
32 32
 
33 33
             $router = new Router(['basePath' => '/']);
34 34
             expect($router->getBasePath())->toBe('');
35 35
         });
36 36
     });
37
-    describe("->getBasePath()", function () {
37
+    describe("->getBasePath()", function() {
38 38
 
39 39
 
40
-        it("sets an empty basePath", function () {
40
+        it("sets an empty basePath", function() {
41 41
 
42 42
 
43 43
             expect($this->router->setBasePath('/'))->toBe($this->router);
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
             expect($this->router->setBasePath(''))->toBe($this->router);
46 46
             expect($this->router->getBasePath())->toBe('');
47 47
         });
48
-        it("adds an leading slash for non empty basePath", function () {
48
+        it("adds an leading slash for non empty basePath", function() {
49 49
 
50 50
 
51 51
             expect($this->router->setBasePath('app'))->toBe($this->router);
@@ -54,24 +54,24 @@  discard block
 block discarded – undo
54 54
             expect($this->router->getBasePath())->toBe('/base');
55 55
         });
56 56
     });
57
-    describe("->bind()", function () {
57
+    describe("->bind()", function() {
58 58
 
59 59
 
60
-        it("binds a named route", function () {
60
+        it("binds a named route", function() {
61 61
 
62 62
 
63 63
             $r = $this->router;
64
-            $route = $r->bind('foo/bar', ['name' => 'foo'], function () {
64
+            $route = $r->bind('foo/bar', ['name' => 'foo'], function() {
65 65
                 return 'hello';
66 66
             });
67 67
             expect(isset($r['foo']))->toBe(true);
68 68
             expect($r['foo'])->toBe($route);
69 69
         });
70
-        it("matches on methods", function () {
70
+        it("matches on methods", function() {
71 71
 
72 72
 
73 73
             $r = $this->router;
74
-            $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function () {
74
+            $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function() {
75 75
             });
76 76
             $route = $r->route('foo/bar', 'POST');
77 77
             expect($route->Methods())->toBe(['POST', 'PUT']);
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`.");
84 84
             }
85 85
         });
86
-        it("supports lowercase method names", function () {
86
+        it("supports lowercase method names", function() {
87 87
 
88 88
 
89 89
             $r = $this->router;
90
-            $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function () {
90
+            $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function() {
91 91
             });
92 92
             $route = $r->route('foo/bar', 'post');
93 93
             expect($route->Methods())->toBe(['POST', 'PUT']);
@@ -99,52 +99,52 @@  discard block
 block discarded – undo
99 99
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`.");
100 100
             }
101 101
         });
102
-        it("matches on same path different methods", function () {
102
+        it("matches on same path different methods", function() {
103 103
 
104 104
             $r = $this->router;
105
-            $r->bind('foo/bar', ['name' => 'foo', 'methods' => ['POST']], function () {
105
+            $r->bind('foo/bar', ['name' => 'foo', 'methods' => ['POST']], function() {
106 106
             });
107
-            $r->bind('foo/bar', ['name' => 'bar', 'methods' => ['PUT']], function () {
107
+            $r->bind('foo/bar', ['name' => 'bar', 'methods' => ['PUT']], function() {
108 108
             });
109 109
             $route = $r->route('foo/bar', 'POST');
110 110
             expect($route->name)->toBe('foo');
111 111
             $route = $r->route('foo/bar', 'PUT');
112 112
             expect($route->name)->toBe('bar');
113 113
         });
114
-        it("throws an exception when the handler is not a closure", function () {
114
+        it("throws an exception when the handler is not a closure", function() {
115 115
 
116 116
 
117
-            $closure = function () {
117
+            $closure = function() {
118 118
 
119 119
                 $r = $this->router;
120 120
                 $r->bind('foo', 'substr');
121 121
             };
122 122
             expect($closure)->toThrow(new RouterException("The handler needs to be an instance of `Closure` or implements the `__invoke()` magic method."));
123 123
         });
124
-        it("throws an exception when trying to use the `'method'` option", function () {
124
+        it("throws an exception when trying to use the `'method'` option", function() {
125 125
 
126 126
 
127
-            $closure = function () {
127
+            $closure = function() {
128 128
 
129 129
                 $r = $this->router;
130
-                $r->bind('foo', ['method' => 'GET'], function () {
130
+                $r->bind('foo', ['method' => 'GET'], function() {
131 131
                 });
132 132
             };
133 133
             expect($closure)->toThrow(new RouterException("Use the `'methods'` option to limit HTTP verbs on a route binding definition."));
134 134
         });
135 135
     });
136
-    describe("->link()", function () {
136
+    describe("->link()", function() {
137 137
 
138 138
 
139
-        it("forwards router base path", function () {
139
+        it("forwards router base path", function() {
140 140
 
141 141
 
142 142
             $r = $this->router;
143 143
             $r->basePath('app');
144 144
 
145
-            $r->group(['host' => 'www.{domain}.com', 'scheme' => 'https'], function ($r) {
145
+            $r->group(['host' => 'www.{domain}.com', 'scheme' => 'https'], function($r) {
146 146
 
147
-                $r->bind('foo/{bar}', ['name' => 'foo'], function () {
147
+                $r->bind('foo/{bar}', ['name' => 'foo'], function() {
148 148
                 });
149 149
             });
150 150
             $link = $r->link('foo', [
@@ -153,28 +153,28 @@  discard block
 block discarded – undo
153 153
             ], ['absolute' => true]);
154 154
             expect($link)->toBe('https://www.example.com/app/foo/baz');
155 155
         });
156
-        it("maintains prefixes in nested routes", function () {
156
+        it("maintains prefixes in nested routes", function() {
157 157
 
158 158
 
159 159
             $r = $this->router;
160
-            $r->group('foo', ['name' => 'foz'], function ($r) {
160
+            $r->group('foo', ['name' => 'foz'], function($r) {
161 161
 
162
-                $r->group('bar', ['name' => 'baz'], function ($r) {
162
+                $r->group('bar', ['name' => 'baz'], function($r) {
163 163
 
164
-                    $r->bind('{var1}', ['name' => 'quz'], function () {
164
+                    $r->bind('{var1}', ['name' => 'quz'], function() {
165 165
                     });
166 166
                 });
167 167
             });
168 168
             $link = $r->link('foz.baz.quz', ['var1' => 'hello']);
169 169
             expect($link)->toBe('/foo/bar/hello');
170 170
         });
171
-        it("persists persisted parameters in a dispatching context", function () {
171
+        it("persists persisted parameters in a dispatching context", function() {
172 172
 
173 173
 
174 174
             $r = $this->router;
175
-            $r->group('{locale:en|fr}', ['persist' => 'locale'], function ($r) {
175
+            $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) {
176 176
 
177
-                $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function () {
177
+                $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function() {
178 178
                 });
179 179
             });
180 180
             $r->route('fr/post/index');
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
             ]);
193 193
             expect($link)->toBe('/en/post/view/5');
194 194
         });
195
-        it("overrides persisted parameters in a dispatching context", function () {
195
+        it("overrides persisted parameters in a dispatching context", function() {
196 196
 
197 197
 
198 198
             $r = $this->router;
199
-            $r->group('{locale:en|fr}', ['persist' => 'locale'], function ($r) {
199
+            $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) {
200 200
 
201
-                $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function () {
201
+                $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function() {
202 202
                 });
203 203
             });
204 204
             $r->route('fr/post/index');
@@ -210,24 +210,24 @@  discard block
 block discarded – undo
210 210
             ]);
211 211
             expect($link)->toBe('/en/post/view/5');
212 212
         });
213
-        it("throws an exception when no route is found for a specified name", function () {
213
+        it("throws an exception when no route is found for a specified name", function() {
214 214
 
215 215
 
216
-            $closure = function () {
216
+            $closure = function() {
217 217
 
218 218
                 $this->router->link('not.binded.yet', []);
219 219
             };
220 220
             expect($closure)->toThrow(new RouterException("No binded route defined for `'not.binded.yet'`, bind it first with `bind()`."));
221 221
         });
222 222
     });
223
-    describe("->route()", function () {
223
+    describe("->route()", function() {
224 224
 
225 225
 
226
-        it("routes on a simple route", function () {
226
+        it("routes on a simple route", function() {
227 227
 
228 228
 
229 229
             $r = $this->router;
230
-            $r->bind('foo/bar', function () {
230
+            $r->bind('foo/bar', function() {
231 231
             });
232 232
             $route = $r->route('foo/bar', 'GET');
233 233
             expect($this->export($route->request))->toEqual([
@@ -242,11 +242,11 @@  discard block
 block discarded – undo
242 242
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`.");
243 243
             }
244 244
         });
245
-        it("routes on a named route", function () {
245
+        it("routes on a named route", function() {
246 246
 
247 247
 
248 248
             $r = $this->router;
249
-            $r->bind('foo/bar', ['name' => 'foo'], function () {
249
+            $r->bind('foo/bar', ['name' => 'foo'], function() {
250 250
             });
251 251
             $route = $r->route('foo/bar', 'GET');
252 252
             expect($route->name)->toBe('foo');
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`.");
257 257
             }
258 258
         });
259
-        it("supports empty as index route", function () {
259
+        it("supports empty as index route", function() {
260 260
 
261 261
 
262 262
             $r = $this->router;
263
-            $r->bind('', function () {
263
+            $r->bind('', function() {
264 264
             });
265 265
             $route = $r->route('', 'GET');
266 266
             expect($this->export($route->request))->toEqual([
@@ -270,11 +270,11 @@  discard block
 block discarded – undo
270 270
                 'path'   => ''
271 271
             ]);
272 272
         });
273
-        it("supports a slash as indes route", function () {
273
+        it("supports a slash as indes route", function() {
274 274
 
275 275
 
276 276
             $r = $this->router;
277
-            $r->bind('/', function () {
277
+            $r->bind('/', function() {
278 278
             });
279 279
             $route = $r->route('', 'GET');
280 280
             expect($this->export($route->request))->toEqual([
@@ -284,11 +284,11 @@  discard block
 block discarded – undo
284 284
                 'path'   => ''
285 285
             ]);
286 286
         });
287
-        it("supports route variables", function () {
287
+        it("supports route variables", function() {
288 288
 
289 289
 
290 290
             $r = $this->router;
291
-            $r->get('foo/{param}', function () {
291
+            $r->get('foo/{param}', function() {
292 292
             });
293 293
             $route = $r->route('foo/bar', 'GET');
294 294
             expect($route->params)->toBe(['param' => 'bar']);
@@ -298,11 +298,11 @@  discard block
 block discarded – undo
298 298
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`.");
299 299
             }
300 300
         });
301
-        it("supports constrained route variables", function () {
301
+        it("supports constrained route variables", function() {
302 302
 
303 303
 
304 304
             $r = $this->router;
305
-            $r->get('foo/{var1:\d+}', function () {
305
+            $r->get('foo/{var1:\d+}', function() {
306 306
             });
307 307
             $route = $r->route('foo/25', 'GET');
308 308
             expect($route->params)->toBe(['var1' => '25']);
@@ -312,22 +312,22 @@  discard block
 block discarded – undo
312 312
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/foo/bar`.");
313 313
             }
314 314
         });
315
-        it("supports optional segments with variables", function () {
315
+        it("supports optional segments with variables", function() {
316 316
 
317 317
 
318 318
             $r = $this->router;
319
-            $r->get('foo[/{var1}]', function () {
319
+            $r->get('foo[/{var1}]', function() {
320 320
             });
321 321
             $route = $r->route('foo', 'GET');
322 322
             expect($route->params)->toBe(['var1' => null]);
323 323
             $route = $r->route('foo/bar', 'GET');
324 324
             expect($route->params)->toBe(['var1' => 'bar']);
325 325
         });
326
-        it("supports repeatable segments", function () {
326
+        it("supports repeatable segments", function() {
327 327
 
328 328
 
329 329
             $r = $this->router;
330
-            $r->get('foo[/:{var1}]*[/bar[/:{var2}]*]', function () {
330
+            $r->get('foo[/:{var1}]*[/bar[/:{var2}]*]', function() {
331 331
             });
332 332
             $route = $r->route('foo', 'GET');
333 333
             expect($route->params)->toBe([
@@ -345,11 +345,11 @@  discard block
 block discarded – undo
345 345
                 'var2' => ['fuz']
346 346
             ]);
347 347
         });
348
-        it("supports optional segments with custom variable regex", function () {
348
+        it("supports optional segments with custom variable regex", function() {
349 349
 
350 350
 
351 351
             $r = $this->router;
352
-            $r->get('foo[/{var1:\d+}]', function () {
352
+            $r->get('foo[/{var1:\d+}]', function() {
353 353
             });
354 354
             $route = $r->route('foo', 'GET');
355 355
             expect($route->params)->toBe(['var1' => null]);
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/foo/baz`.");
362 362
             }
363 363
         });
364
-        it("supports multiple optional segments", function () {
364
+        it("supports multiple optional segments", function() {
365 365
 
366 366
 
367 367
             $patterns = [
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
             $r = $this->router;
371 371
 
372 372
             foreach ($patterns as $pattern) {
373
-                $r->get($pattern, function () {
373
+                $r->get($pattern, function() {
374 374
                 });
375 375
                 $route = $r->route('foo', 'GET');
376 376
                 expect($route->params)->toBe(['var1' => 'foo', 'var2' => null]);
@@ -379,13 +379,13 @@  discard block
 block discarded – undo
379 379
                 $r->clear();
380 380
             };
381 381
         });
382
-        it("supports host variables", function () {
382
+        it("supports host variables", function() {
383 383
 
384 384
 
385 385
             $r = $this->router;
386
-            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function () {
386
+            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function() {
387 387
             });
388
-            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function () {
388
+            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function() {
389 389
             });
390 390
             $route = $r->route('foo/25', 'GET', 'foo.biz.bar');
391 391
             expect($route->Host()->getPattern())->toBe('foo.{domain}.bar');
@@ -394,27 +394,27 @@  discard block
 block discarded – undo
394 394
             expect($route->Host()->getPattern())->toBe('foo.{domain}.baz');
395 395
             expect($route->params)->toBe(['domain' => 'buz', 'var1' => '50']);
396 396
         });
397
-        it("supports constrained host variables", function () {
397
+        it("supports constrained host variables", function() {
398 398
 
399 399
 
400 400
             $r = $this->router;
401
-            $r->get('foo/{var1:\d+}', ['host' => '{subdomain:foo}.{domain}.bar'], function () {
401
+            $r->get('foo/{var1:\d+}', ['host' => '{subdomain:foo}.{domain}.bar'], function() {
402 402
             });
403 403
             $route = $r->route('foo/25', 'GET', 'foo.biz.bar');
404
-            expect($route->params)->toBe([ 'subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']);
404
+            expect($route->params)->toBe(['subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']);
405 405
             try {
406 406
                 $route = $r->route('foo/bar', 'GET', 'foo.biz.bar');
407 407
             } catch (RouteNotFoundException $e) {
408 408
                 expect($e->getMessage())->toBe("No route found for `*:foo.biz.bar:GET:/foo/bar`.");
409 409
             }
410 410
         });
411
-        it("supports absolute URL", function () {
411
+        it("supports absolute URL", function() {
412 412
 
413 413
 
414 414
             $r = $this->router;
415
-            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function () {
415
+            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function() {
416 416
             });
417
-            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function () {
417
+            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function() {
418 418
             });
419 419
             $route = $r->route('http://foo.biz.bar/foo/25', 'GET');
420 420
             expect($route->Host()->getPattern())->toBe('foo.{domain}.bar');
@@ -423,23 +423,23 @@  discard block
 block discarded – undo
423 423
             expect($route->Host()->getPattern())->toBe('foo.{domain}.baz');
424 424
             expect($route->params)->toBe(['domain' => 'buz', 'var1' => '50']);
425 425
         });
426
-        it("supports RESTful routes", function () {
426
+        it("supports RESTful routes", function() {
427 427
 
428 428
 
429 429
             $r = $this->router;
430
-            $r->get('foo/bar', function () {
430
+            $r->get('foo/bar', function() {
431 431
             });
432
-            $r->head('foo/bar', function () {
432
+            $r->head('foo/bar', function() {
433 433
             });
434
-            $r->post('foo/bar', function () {
434
+            $r->post('foo/bar', function() {
435 435
             });
436
-            $r->put('foo/bar', function () {
436
+            $r->put('foo/bar', function() {
437 437
             });
438
-            $r->patch('foo/bar', function () {
438
+            $r->patch('foo/bar', function() {
439 439
             });
440
-            $r->delete('foo/bar', function () {
440
+            $r->delete('foo/bar', function() {
441 441
             });
442
-            $r->options('foo/bar', function () {
442
+            $r->options('foo/bar', function() {
443 443
             });
444 444
             $methods = ['OPTIONS', 'DELETE', 'PATCH', 'PUT', 'POST', 'HEAD', 'GET'];
445 445
             $route = $r->route('foo/bar', 'GET');
@@ -457,11 +457,11 @@  discard block
 block discarded – undo
457 457
             $route = $r->route('foo/bar', 'OPTIONS');
458 458
             expect($route->Methods())->toBe($methods);
459 459
         });
460
-        it("matches relationships based routes", function () {
460
+        it("matches relationships based routes", function() {
461 461
 
462 462
 
463 463
             $r = $this->router;
464
-            $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function () {
464
+            $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function() {
465 465
             });
466 466
             $route = $r->route('blog/1/post/22/comment/:show', 'GET');
467 467
             expect($route->params)->toBe([
@@ -473,35 +473,35 @@  discard block
 block discarded – undo
473 473
                 'action' => 'show'
474 474
             ]);
475 475
         });
476
-        it("dispatches HEAD requests on matching GET routes if the HEAD routes are missing", function () {
476
+        it("dispatches HEAD requests on matching GET routes if the HEAD routes are missing", function() {
477 477
 
478 478
 
479 479
             $r = $this->router;
480
-            $r->get('foo/bar', function () {
480
+            $r->get('foo/bar', function() {
481 481
                 return 'GET';
482 482
             });
483 483
             $route = $r->route('foo/bar', 'HEAD');
484 484
             expect($route->Methods())->toBe(['GET']);
485 485
         });
486
-        it("dispatches HEAD requests on matching HEAD routes", function () {
486
+        it("dispatches HEAD requests on matching HEAD routes", function() {
487 487
 
488 488
 
489 489
             $r = $this->router;
490 490
 
491
-            $r->head('foo/bar', function () {
491
+            $r->head('foo/bar', function() {
492 492
                 return 'HEAD';
493 493
             });
494
-            $r->get('foo/bar', function () {
494
+            $r->get('foo/bar', function() {
495 495
                 return 'GET';
496 496
             });
497 497
             $route = $r->route('foo/bar', 'HEAD');
498 498
             expect($route->Methods())->toBe(['GET', 'HEAD']);
499 499
         });
500
-        it("supports requests as a list of arguments", function () {
500
+        it("supports requests as a list of arguments", function() {
501 501
 
502 502
 
503 503
             $r = $this->router;
504
-            $r->bind('foo/bar', function () {
504
+            $r->bind('foo/bar', function() {
505 505
             });
506 506
             $route = $r->route('foo/bar', 'GET');
507 507
             expect($this->export($route->request))->toEqual([
@@ -511,10 +511,10 @@  discard block
 block discarded – undo
511 511
                 'path'   => 'foo/bar'
512 512
             ]);
513 513
         });
514
-        it("supports requests as an object", function () {
514
+        it("supports requests as an object", function() {
515 515
 
516 516
             $r = $this->router;
517
-            $r->bind('foo/bar', function () {
517
+            $r->bind('foo/bar', function() {
518 518
             });
519 519
             $request = Double::instance(['implements' => ServerRequestInterface::class]);
520 520
             $uri = Double::instance(['implements' => UriInterface::class]);
@@ -527,11 +527,11 @@  discard block
 block discarded – undo
527 527
             $route = $r->route($request, 'GET');
528 528
             expect($route->request)->toBe($request);
529 529
         });
530
-        it("supports requests as an array", function () {
530
+        it("supports requests as an array", function() {
531 531
 
532 532
 
533 533
             $r = $this->router;
534
-            $r->bind('foo/bar', function () {
534
+            $r->bind('foo/bar', function() {
535 535
             });
536 536
             $route = $r->route(['path' => 'foo/bar'], 'GET');
537 537
             expect($this->export($route->request))->toEqual([
@@ -542,59 +542,59 @@  discard block
 block discarded – undo
542 542
             ]);
543 543
         });
544 544
     });
545
-    describe("->group()", function () {
545
+    describe("->group()", function() {
546 546
 
547 547
 
548
-        it("supports nested named route", function () {
548
+        it("supports nested named route", function() {
549 549
 
550 550
 
551 551
             $r = $this->router;
552
-            $r->group('foo', ['name' => 'foz'], function ($r) use (&$route) {
552
+            $r->group('foo', ['name' => 'foz'], function($r) use (&$route) {
553 553
 
554
-                $r->group('bar', ['name' => 'baz'], function ($r) use (&$route) {
554
+                $r->group('bar', ['name' => 'baz'], function($r) use (&$route) {
555 555
 
556
-                    $route = $r->bind('{var1}', ['name' => 'quz'], function () {
556
+                    $route = $r->bind('{var1}', ['name' => 'quz'], function() {
557 557
                     });
558 558
                 });
559 559
             });
560 560
             expect(isset($r['foz.baz.quz']))->toBe(true);
561 561
             expect($r['foz.baz.quz'])->toBe($route);
562 562
         });
563
-        it("returns a working scope", function () {
563
+        it("returns a working scope", function() {
564 564
 
565 565
 
566 566
             $r = $this->router;
567
-            $route = $r->group('foo', ['name' => 'foz'], function () {
568
-            })->group('bar', ['name' => 'baz'], function () {
569
-            })->bind('{var1}', ['name' => 'quz'], function () {
567
+            $route = $r->group('foo', ['name' => 'foz'], function() {
568
+            })->group('bar', ['name' => 'baz'], function() {
569
+            })->bind('{var1}', ['name' => 'quz'], function() {
570 570
             });
571 571
             expect(isset($r['foz.baz.quz']))->toBe(true);
572 572
             expect($r['foz.baz.quz'])->toBe($route);
573 573
         });
574
-        context("with a prefix contraint", function () {
574
+        context("with a prefix contraint", function() {
575 575
 
576 576
 
577
-            beforeEach(function () {
577
+            beforeEach(function() {
578 578
 
579 579
 
580 580
                 $r = $this->router;
581
-                $r->group('foo', function ($r) {
581
+                $r->group('foo', function($r) {
582 582
 
583
-                    $r->bind('{var1}', function () {
583
+                    $r->bind('{var1}', function() {
584 584
                     });
585 585
                 });
586 586
             });
587
-            it("respects url's prefix constraint", function () {
587
+            it("respects url's prefix constraint", function() {
588 588
 
589 589
 
590 590
                 $r = $this->router;
591 591
                 $route = $r->route('foo/bar');
592 592
                 expect($route->params)->toBe(['var1'   => 'bar']);
593 593
             });
594
-            it("throws an exception when the prefix does not match", function () {
594
+            it("throws an exception when the prefix does not match", function() {
595 595
 
596 596
 
597
-                $closure = function () {
597
+                $closure = function() {
598 598
 
599 599
                     $r = $this->router;
600 600
                     $route = $r->route('bar/foo', 'GET');
@@ -602,30 +602,30 @@  discard block
 block discarded – undo
602 602
                 expect($closure)->toThrow(new RouteNotFoundException("No route found for `*:*:GET:/bar/foo`."));
603 603
             });
604 604
         });
605
-        context("with a prefix contraint and an optional parameter", function () {
605
+        context("with a prefix contraint and an optional parameter", function() {
606 606
 
607 607
 
608
-            beforeEach(function () {
608
+            beforeEach(function() {
609 609
 
610 610
 
611 611
                 $r = $this->router;
612
-                $r->group('foo', function ($r) {
612
+                $r->group('foo', function($r) {
613 613
 
614
-                    $r->bind('[{var1}]', function () {
614
+                    $r->bind('[{var1}]', function() {
615 615
                     });
616 616
                 });
617 617
             });
618
-            it("respects url's prefix constraint", function () {
618
+            it("respects url's prefix constraint", function() {
619 619
 
620 620
 
621 621
                 $r = $this->router;
622 622
                 $route = $r->route('foo');
623 623
                 expect($route->params)->toBe(['var1' => null]);
624 624
             });
625
-            it("throws an exception when the prefix does not match", function () {
625
+            it("throws an exception when the prefix does not match", function() {
626 626
 
627 627
 
628
-                $closure = function () {
628
+                $closure = function() {
629 629
 
630 630
                     $r = $this->router;
631 631
                     $route = $r->route('bar/foo', 'GET');
@@ -633,23 +633,23 @@  discard block
 block discarded – undo
633 633
                 expect($closure)->toThrow(new RouteNotFoundException("No route found for `*:*:GET:/bar/foo`."));
634 634
             });
635 635
         });
636
-        context("with a host constraint", function () {
636
+        context("with a host constraint", function() {
637 637
 
638 638
 
639
-            beforeEach(function () {
639
+            beforeEach(function() {
640 640
 
641 641
 
642 642
                 $r = $this->router;
643
-                $r->group('foo', ['host' => 'foo.{domain}.bar'], function ($r) {
643
+                $r->group('foo', ['host' => 'foo.{domain}.bar'], function($r) {
644 644
 
645
-                    $r->group('bar', function ($r) {
645
+                    $r->group('bar', function($r) {
646 646
 
647
-                        $r->bind('{var1}', function () {
647
+                        $r->bind('{var1}', function() {
648 648
                         });
649 649
                     });
650 650
                 });
651 651
             });
652
-            it("respects url's host constraint", function () {
652
+            it("respects url's host constraint", function() {
653 653
 
654 654
 
655 655
                 $r = $this->router;
@@ -659,10 +659,10 @@  discard block
 block discarded – undo
659 659
                     'var1'   => 'baz'
660 660
                 ]);
661 661
             });
662
-            it("throws an exception when the host does not match", function () {
662
+            it("throws an exception when the host does not match", function() {
663 663
 
664 664
 
665
-                $closure = function () {
665
+                $closure = function() {
666 666
 
667 667
                     $r = $this->router;
668 668
                     $route = $r->route('http://bar.hello.foo/foo/bar/baz', 'GET');
@@ -670,23 +670,23 @@  discard block
 block discarded – undo
670 670
                 expect($closure)->toThrow(new RouteNotFoundException("No route found for `http:bar.hello.foo:GET:/foo/bar/baz`."));
671 671
             });
672 672
         });
673
-        context("with a scheme constraint", function () {
673
+        context("with a scheme constraint", function() {
674 674
 
675 675
 
676
-            beforeEach(function () {
676
+            beforeEach(function() {
677 677
 
678 678
 
679 679
                 $r = $this->router;
680
-                $r->group('foo', ['scheme' => 'http'], function ($r) {
680
+                $r->group('foo', ['scheme' => 'http'], function($r) {
681 681
 
682
-                    $r->group('bar', function ($r) {
682
+                    $r->group('bar', function($r) {
683 683
 
684
-                        $r->bind('{var1}', function () {
684
+                        $r->bind('{var1}', function() {
685 685
                         });
686 686
                     });
687 687
                 });
688 688
             });
689
-            it("respects url's scheme constraint", function () {
689
+            it("respects url's scheme constraint", function() {
690 690
 
691 691
 
692 692
                 $r = $this->router;
@@ -695,10 +695,10 @@  discard block
 block discarded – undo
695 695
                     'var1'   => 'baz'
696 696
                 ]);
697 697
             });
698
-            it("throws an exception when route is not found", function () {
698
+            it("throws an exception when route is not found", function() {
699 699
 
700 700
 
701
-                $closure = function () {
701
+                $closure = function() {
702 702
 
703 703
                     $r = $this->router;
704 704
                     $route = $r->route('https://domain.com/foo/bar/baz', 'GET');
@@ -706,25 +706,25 @@  discard block
 block discarded – undo
706 706
                 expect($closure)->toThrow(new RouteNotFoundException("No route found for `https:domain.com:GET:/foo/bar/baz`."));
707 707
             });
708 708
         });
709
-        it("concats namespace values", function () {
709
+        it("concats namespace values", function() {
710 710
 
711 711
 
712 712
             $r = $this->router;
713
-            $r->group('foo', ['namespace' => 'My'], function ($r) {
713
+            $r->group('foo', ['namespace' => 'My'], function($r) {
714 714
 
715
-                $r->group('bar', ['namespace' => 'Name'], function ($r) {
715
+                $r->group('bar', ['namespace' => 'Name'], function($r) {
716 716
 
717
-                    $r->bind('{var1}', ['namespace' => 'Space'], function () {
717
+                    $r->bind('{var1}', ['namespace' => 'Space'], function() {
718 718
                     });
719 719
                 });
720 720
             });
721 721
             $route = $r->route('foo/bar/baz', 'GET');
722 722
             expect($route->namespace)->toBe('My\Name\Space\\');
723 723
         });
724
-        it("throws an exception when the handler is not a closure", function () {
724
+        it("throws an exception when the handler is not a closure", function() {
725 725
 
726 726
 
727
-            $closure = function () {
727
+            $closure = function() {
728 728
 
729 729
                 $r = $this->router;
730 730
                 $r->group('foo', 'substr');
@@ -732,24 +732,24 @@  discard block
 block discarded – undo
732 732
             expect($closure)->toThrow(new RouterException("The handler needs to be an instance of `Closure` or implements the `__invoke()` magic method."));
733 733
         });
734 734
     });
735
-    describe("->middleware()", function () {
735
+    describe("->middleware()", function() {
736 736
 
737 737
 
738
-        it("returns global middleware", function () {
738
+        it("returns global middleware", function() {
739 739
 
740 740
 
741 741
             $r = $this->router;
742
-            $mw1 = function ($request, $response, $next) {
742
+            $mw1 = function($request, $response, $next) {
743 743
 
744
-                return '1' . $next() . '1';
744
+                return '1'.$next().'1';
745 745
             };
746
-            $mw2 = function ($request, $response, $next) {
746
+            $mw2 = function($request, $response, $next) {
747 747
 
748
-                return '2' . $next() . '2';
748
+                return '2'.$next().'2';
749 749
             };
750 750
             $r->apply($mw1, $mw2);
751 751
 
752
-            $next = function () {
752
+            $next = function() {
753 753
                 return '';
754 754
             };
755 755
             $generator = $r->middleware();
@@ -760,21 +760,21 @@  discard block
 block discarded – undo
760 760
             expect($actual1(null, null, $next))->toBe('11');
761 761
         });
762 762
     });
763
-    describe("->apply()", function () {
763
+    describe("->apply()", function() {
764 764
 
765 765
 
766
-        it("applies middlewares globally", function () {
766
+        it("applies middlewares globally", function() {
767 767
 
768 768
 
769 769
             $r = $this->router;
770
-            $r->apply(function ($request, $response, $next) {
770
+            $r->apply(function($request, $response, $next) {
771 771
 
772
-                return '1' . $next() . '1';
773
-            })->apply(function ($request, $response, $next) {
772
+                return '1'.$next().'1';
773
+            })->apply(function($request, $response, $next) {
774 774
 
775
-                return '2' . $next() . '2';
775
+                return '2'.$next().'2';
776 776
             });
777
-            $route = $r->bind('/foo/bar', function ($route) {
777
+            $route = $r->bind('/foo/bar', function($route) {
778 778
 
779 779
                 return 'A';
780 780
             });
@@ -782,27 +782,27 @@  discard block
 block discarded – undo
782 782
             $actual = $route->dispatch();
783 783
             expect($actual)->toBe('21A12');
784 784
         });
785
-        it("applies middlewares globally and per groups", function () {
785
+        it("applies middlewares globally and per groups", function() {
786 786
 
787 787
 
788 788
             $r = $this->router;
789
-            $r->apply(function ($request, $response, $next) {
789
+            $r->apply(function($request, $response, $next) {
790 790
 
791
-                return '1' . $next() . '1';
791
+                return '1'.$next().'1';
792 792
             });
793
-            $r->bind('foo/{foo}', ['name' => 'foo'], function () {
793
+            $r->bind('foo/{foo}', ['name' => 'foo'], function() {
794 794
 
795 795
                 return 'A';
796 796
             });
797
-            $r->group('bar', function ($r) {
797
+            $r->group('bar', function($r) {
798 798
 
799
-                $r->bind('{bar}', ['name' => 'bar'], function () {
799
+                $r->bind('{bar}', ['name' => 'bar'], function() {
800 800
 
801 801
                     return 'A';
802 802
                 });
803
-            })->apply(function ($request, $response, $next) {
803
+            })->apply(function($request, $response, $next) {
804 804
 
805
-                return '2' . $next() . '2';
805
+                return '2'.$next().'2';
806 806
             });
807 807
             $route = $r->route('foo/foo');
808 808
             $actual = $route->dispatch();
@@ -812,15 +812,15 @@  discard block
 block discarded – undo
812 812
             expect($actual)->toBe('21A12');
813 813
         });
814 814
     });
815
-    describe("->strategy()", function () {
815
+    describe("->strategy()", function() {
816 816
 
817 817
 
818
-        it("sets a strategy", function () {
818
+        it("sets a strategy", function() {
819 819
 
820 820
             $r = $this->router;
821
-            $mystrategy = function ($router) {
821
+            $mystrategy = function($router) {
822 822
 
823
-                $router->bind('foo/bar', function () {
823
+                $router->bind('foo/bar', function() {
824 824
 
825 825
                     return 'Hello World!';
826 826
                 });
@@ -831,11 +831,11 @@  discard block
 block discarded – undo
831 831
             $route = $r->route('foo/bar');
832 832
             expect($route->Pattern())->toBe('/foo/bar');
833 833
         });
834
-        it("unsets a strategy", function () {
834
+        it("unsets a strategy", function() {
835 835
 
836 836
             $r = $this->router;
837 837
 
838
-            $mystrategy = function () {
838
+            $mystrategy = function() {
839 839
             };
840 840
             $r->setStrategy('mystrategy', $mystrategy);
841 841
             expect($r->strategy('mystrategy'))->toBe($mystrategy);
Please login to merge, or discard this patch.