Passed
Push — refactor ( 885968...d87829 )
by Florian
02:43
created
spec/Suite/Parser.spec.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
 use Lead\Router\Exception\ParserException;
8 8
 use Lead\Router\Parser;
9 9
 
10
-describe("Parser", function () {
10
+describe("Parser", function() {
11 11
 
12 12
 
13
-    describe("::tokenize()", function () {
13
+    describe("::tokenize()", function() {
14 14
 
15 15
 
16
-        it("parses an empty url", function () {
16
+        it("parses an empty url", function() {
17 17
 
18 18
 
19 19
             $result = Parser::tokenize('');
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
                 'tokens'   => []
26 26
             ]);
27 27
         });
28
-        it("parses a static url", function () {
28
+        it("parses a static url", function() {
29 29
 
30 30
 
31 31
             $result = Parser::tokenize('/test');
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
                 'tokens'   => ['/test']
38 38
             ]);
39 39
         });
40
-        it("parses an url with a variable", function () {
40
+        it("parses an url with a variable", function() {
41 41
 
42 42
 
43 43
             $result = Parser::tokenize('/test/{param}');
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
                 ]
56 56
             ]);
57 57
         });
58
-        it("parses an url with several variables", function () {
58
+        it("parses an url with several variables", function() {
59 59
 
60 60
 
61 61
             $result = Parser::tokenize('/test/{param1}/test2/{param2}');
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
                 ]
79 79
             ]);
80 80
         });
81
-        it("parses an url with a variable with a custom regex", function () {
81
+        it("parses an url with a variable with a custom regex", function() {
82 82
 
83 83
 
84 84
             $result = Parser::tokenize('/test/{param:\d+}');
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
                 ]
97 97
             ]);
98 98
         });
99
-        it("parses an url with an optional segment", function () {
99
+        it("parses an url with an optional segment", function() {
100 100
 
101 101
 
102 102
             $result = Parser::tokenize('/test[opt]');
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
                 ]
120 120
             ]);
121 121
         });
122
-        it("parses an optional segment", function () {
122
+        it("parses an optional segment", function() {
123 123
 
124 124
 
125 125
             $result = Parser::tokenize('[test]');
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
                 ]
142 142
             ]);
143 143
         });
144
-        it("parses an optional segment inside a route definition", function () {
144
+        it("parses an optional segment inside a route definition", function() {
145 145
 
146 146
 
147 147
             $result = Parser::tokenize('/test[/opt]/required');
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                 ]
166 166
             ]);
167 167
         });
168
-        it("parses an url with an optional variable", function () {
168
+        it("parses an url with an optional variable", function() {
169 169
 
170 170
 
171 171
             $result = Parser::tokenize('/test[/{param}]');
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
                 ]
193 193
             ]);
194 194
         });
195
-        it("parses an url with a variable with a prefix and a suffix inside an optional segment", function () {
195
+        it("parses an url with a variable with a prefix and a suffix inside an optional segment", function() {
196 196
 
197 197
 
198 198
             $result = Parser::tokenize('/test[/:{param}:]');
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
                 ]
221 221
             ]);
222 222
         });
223
-        it("parses an url with a variable and an optional segment", function () {
223
+        it("parses an url with a variable and an optional segment", function() {
224 224
 
225 225
 
226 226
             $result = Parser::tokenize('/{param}[opt]');
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
                 ]
248 248
             ]);
249 249
         });
250
-        it("parses nested segments", function () {
250
+        it("parses nested segments", function() {
251 251
 
252 252
 
253 253
             $result = Parser::tokenize('/test[/{name}[/{id:[0-9]+}]]');
@@ -287,25 +287,25 @@  discard block
 block discarded – undo
287 287
                 ]
288 288
             ]);
289 289
         });
290
-        it("throws an exception when there's a missing closing square bracket", function () {
290
+        it("throws an exception when there's a missing closing square bracket", function() {
291 291
 
292 292
 
293
-            $closure = function () {
293
+            $closure = function() {
294 294
 
295 295
                 Parser::tokenize('/test[opt');
296 296
             };
297 297
             expect($closure)->toThrow(ParserException::squareBracketMismatch());
298
-            $closure = function () {
298
+            $closure = function() {
299 299
 
300 300
                 Parser::tokenize('/test[opt[opt2]');
301 301
             };
302 302
             expect($closure)->toThrow(ParserException::squareBracketMismatch());
303 303
         });
304 304
     });
305
-    describe("::compile()", function () {
305
+    describe("::compile()", function() {
306 306
 
307 307
 
308
-        it("compiles a tokens structure", function () {
308
+        it("compiles a tokens structure", function() {
309 309
 
310 310
 
311 311
             $token = Parser::tokenize('/test[/{name}[/{id:[0-9]+}]]');
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
                 '/test(?:/([^/]+)(?:/([0-9]+))?)?', ['name' => false, 'id' => false]
315 315
             ]);
316 316
         });
317
-        it("compiles a tokens structure with repeatable patterns", function () {
317
+        it("compiles a tokens structure with repeatable patterns", function() {
318 318
 
319 319
 
320 320
             $tokens = Parser::tokenize('/test[/{name}[/{id:[0-9]+}]*]');
@@ -323,28 +323,28 @@  discard block
 block discarded – undo
323 323
                 '/test(?:/([^/]+)((?:/[0-9]+)*))?', ['name' => false, 'id' => '/{id:[0-9]+}']
324 324
             ]);
325 325
         });
326
-        it("throws an exception when a placeholder is present several time", function () {
326
+        it("throws an exception when a placeholder is present several time", function() {
327 327
 
328 328
 
329
-            $closure = function () {
329
+            $closure = function() {
330 330
 
331 331
                 Parser::compile(Parser::tokenize('/test/{var}/{var}'));
332 332
             };
333 333
             expect($closure)->toThrow(ParserException::duplicatePlaceholder('var'));
334 334
         });
335
-        it("throws an exception when a placeholder is present several time through different segments", function () {
335
+        it("throws an exception when a placeholder is present several time through different segments", function() {
336 336
 
337 337
 
338
-            $closure = function () {
338
+            $closure = function() {
339 339
 
340 340
                 Parser::compile(Parser::tokenize('/test/{var}[/{var}]'));
341 341
             };
342 342
             expect($closure)->toThrow(ParserException::duplicatePlaceholder('var'));
343 343
         });
344
-        it("throws an exception when multiple placeholder are present in repeatable segments", function () {
344
+        it("throws an exception when multiple placeholder are present in repeatable segments", function() {
345 345
 
346 346
 
347
-            $closure = function () {
347
+            $closure = function() {
348 348
 
349 349
                 Parser::compile(Parser::tokenize('/test[/{var1}/{var2}]*'));
350 350
             };
Please login to merge, or discard this patch.
src/Scope.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -94,12 +94,12 @@  discard block
 block discarded – undo
94 94
         $scope = $this->scope;
95 95
 
96 96
         if (!empty($options['name'])) {
97
-            $options['name'] = $scope['name'] ? $scope['name'] . '.' . $options['name'] : $options['name'];
97
+            $options['name'] = $scope['name'] ? $scope['name'].'.'.$options['name'] : $options['name'];
98 98
         }
99 99
 
100 100
         if (!empty($options['prefix'])) {
101
-            $options['prefix'] = $scope['prefix'] . trim($options['prefix'], '/');
102
-            $options['prefix'] = $options['prefix'] ? $options['prefix'] . '/' : '';
101
+            $options['prefix'] = $scope['prefix'].trim($options['prefix'], '/');
102
+            $options['prefix'] = $options['prefix'] ? $options['prefix'].'/' : '';
103 103
         }
104 104
 
105 105
         if (isset($options['persist'])) {
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         }
108 108
 
109 109
         if (isset($options['namespace'])) {
110
-            $options['namespace'] = $scope['namespace'] . trim($options['namespace'], '\\') . '\\';
110
+            $options['namespace'] = $scope['namespace'].trim($options['namespace'], '\\').'\\';
111 111
         }
112 112
 
113 113
         return $options + $scope;
Please login to merge, or discard this patch.
src/Parser.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     public static function tokenize(string $pattern, string $delimiter = '/'): array
81 81
     {
82 82
         // Checks if the pattern has some optional segments.
83
-        if (count(preg_split('~' . static::PLACEHOLDER_REGEX . '(*SKIP)(*F)|\[~x', $pattern)) > 1) {
83
+        if (count(preg_split('~'.static::PLACEHOLDER_REGEX.'(*SKIP)(*F)|\[~x', $pattern)) > 1) {
84 84
             $tokens = static::_tokenizePattern($pattern, $delimiter);
85 85
         } else {
86 86
             $tokens = static::tokenizeSegment($pattern, $delimiter);
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
         $tokens = [];
144 144
         $index = 0;
145 145
         $path = '';
146
-        if (preg_match_all('~' . static::PLACEHOLDER_REGEX . '()~x', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
146
+        if (preg_match_all('~'.static::PLACEHOLDER_REGEX.'()~x', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
147 147
             foreach ($matches as $match) {
148 148
                 $offset = $match[0][1];
149 149
                 $path .= substr($pattern, $index, $offset - $index);
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
                 }
155 155
 
156 156
                 $variable = $match[1][0];
157
-                $capture = $match[2][0] ?: '[^' . $delimiter . ']+';
157
+                $capture = $match[2][0] ?: '[^'.$delimiter.']+';
158 158
                 $tokens[] = [
159 159
                     'name'      => $variable,
160 160
                     'pattern'   => $capture
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
                     if (count($rule[1]) > 1) {
260 260
                         throw ParserException::placeholderExceeded();
261 261
                     }
262
-                    $regex .= '((?:' . $rule[0] . ')' . $child['greedy'] . ')';
262
+                    $regex .= '((?:'.$rule[0].')'.$child['greedy'].')';
263 263
                 } elseif ($child['optional']) {
264
-                    $regex .= '(?:' . $rule[0] . ')?';
264
+                    $regex .= '(?:'.$rule[0].')?';
265 265
                 }
266 266
                 foreach ($rule[1] as $name => $pattern) {
267 267
                     if (isset($variables[$name])) {
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
                     $regex .= $child['pattern'];
280 280
                 } else {
281 281
                     $variables[$name] = false;
282
-                    $regex .= '(' . $child['pattern'] . ')';
282
+                    $regex .= '('.$child['pattern'].')';
283 283
                 }
284 284
             }
285 285
         }
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -70,12 +70,12 @@
 block discarded – undo
70 70
 \}
71 71
 EOD;
72 72
 /**
73
-     * Tokenizes a route pattern. Optional segments are identified by square brackets.
74
-     *
75
-     * @param string $pattern A route pattern
76
-     * @param string $delimiter The path delimiter.
77
-     * @return array
78
-     */
73
+ * Tokenizes a route pattern. Optional segments are identified by square brackets.
74
+ *
75
+ * @param string $pattern A route pattern
76
+ * @param string $delimiter The path delimiter.
77
+ * @return array
78
+ */
79 79
     public static function tokenize(string $pattern, string $delimiter = '/'): array
80 80
     {
81 81
         // Checks if the pattern has some optional segments.
Please login to merge, or discard this patch.
src/RouteInterface.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -81,17 +81,17 @@
 block discarded – undo
81 81
     public function match($request, &$variables = null, &$hostVariables = null): bool;
82 82
 
83 83
     /**
84
-      * Returns the route's link.
85
-      *
86
-      * @param  array $params  The route parameters.
87
-      * @param  array $options Options for generating the proper prefix. Accepted values are:
88
-      *                        - `'absolute'` _boolean_: `true` or `false`. - `'scheme'`
89
-      *                        _string_ : The scheme. - `'host'`     _string_ : The host
90
-      *                        name. - `'basePath'` _string_ : The base path. - `'query'`
91
-      *                        _string_ : The query string. - `'fragment'` _string_ : The
92
-      *                        fragment string.
93
-      * @return string          The link.
94
-      */
84
+     * Returns the route's link.
85
+     *
86
+     * @param  array $params  The route parameters.
87
+     * @param  array $options Options for generating the proper prefix. Accepted values are:
88
+     *                        - `'absolute'` _boolean_: `true` or `false`. - `'scheme'`
89
+     *                        _string_ : The scheme. - `'host'`     _string_ : The host
90
+     *                        name. - `'basePath'` _string_ : The base path. - `'query'`
91
+     *                        _string_ : The query string. - `'fragment'` _string_ : The
92
+     *                        fragment string.
93
+     * @return string          The link.
94
+     */
95 95
     public function link(array $params = [], array $options = []): string;
96 96
 
97 97
     /**
Please login to merge, or discard this patch.
spec/Suite/Route.spec.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@  discard block
 block discarded – undo
11 11
 use Lead\Router\Router;
12 12
 use Lead\Router\Route;
13 13
 
14
-describe("Route", function () {
14
+describe("Route", function() {
15 15
 
16 16
 
17
-    describe("->pattern()", function () {
17
+    describe("->pattern()", function() {
18 18
 
19 19
 
20
-        it("gets/sets the pattern", function () {
20
+        it("gets/sets the pattern", function() {
21 21
 
22 22
 
23 23
             $route = new Route();
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
                 'paths' => '/{paths}'
30 30
             ]);
31 31
         });
32
-        it("updates the regex", function () {
32
+        it("updates the regex", function() {
33 33
 
34 34
 
35 35
             $route = new Route();
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
             expect($route->setPattern('/foo/baz/{id}[/{paths}]*'))->toBe($route);
39 39
             expect($route->Regex())->toBe('/foo/baz/([^/]+)((?:/[^/]+)*)');
40 40
         });
41
-        it("updates the variables", function () {
41
+        it("updates the variables", function() {
42 42
 
43 43
 
44 44
             $route = new Route();
@@ -54,10 +54,10 @@  discard block
 block discarded – undo
54 54
             ]);
55 55
         });
56 56
     });
57
-    describe("->scope()", function () {
57
+    describe("->scope()", function() {
58 58
 
59 59
 
60
-        it("gets/sets route scope", function () {
60
+        it("gets/sets route scope", function() {
61 61
 
62 62
 
63 63
             $scope = new Scope();
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
             expect($route->Scope())->toBe($scope);
67 67
         });
68 68
     });
69
-    describe("->methods()", function () {
69
+    describe("->methods()", function() {
70 70
 
71 71
 
72
-        it("gets/sets route methods", function () {
72
+        it("gets/sets route methods", function() {
73 73
 
74 74
 
75 75
             $route = new Route();
76 76
             expect($route->setMethods(['POST', 'PUT']))->toBe($route);
77 77
             expect($route->Methods())->toBe(['POST', 'PUT']);
78 78
         });
79
-        it("formats method names", function () {
79
+        it("formats method names", function() {
80 80
 
81 81
 
82 82
             $route = new Route();
@@ -84,17 +84,17 @@  discard block
 block discarded – undo
84 84
             expect($route->Methods())->toBe(['POST', 'PUT']);
85 85
         });
86 86
     });
87
-    describe("->allow()", function () {
87
+    describe("->allow()", function() {
88 88
 
89 89
 
90
-        it("adds some extra allowed methods", function () {
90
+        it("adds some extra allowed methods", function() {
91 91
 
92 92
 
93 93
             $route = new Route(['methods' => []]);
94 94
             expect($route->allow(['POST', 'PUT']))->toBe($route);
95 95
             expect($route->Methods())->toBe(['POST', 'PUT']);
96 96
         });
97
-        it("formats newly allowed method names", function () {
97
+        it("formats newly allowed method names", function() {
98 98
 
99 99
 
100 100
             $route = new Route(['methods' => []]);
@@ -102,39 +102,39 @@  discard block
 block discarded – undo
102 102
             expect($route->Methods())->toBe(['POST', 'PUT']);
103 103
         });
104 104
     });
105
-    describe("->apply()", function () {
105
+    describe("->apply()", function() {
106 106
 
107 107
 
108
-        it("applies middlewares", function () {
108
+        it("applies middlewares", function() {
109 109
 
110 110
 
111 111
             $r = new Router();
112
-            $route = $r->bind('foo/bar', function ($route) {
112
+            $route = $r->bind('foo/bar', function($route) {
113 113
 
114 114
                 return 'A';
115
-            })->apply(function ($request, $response, $next) {
115
+            })->apply(function($request, $response, $next) {
116 116
 
117
-                return '1' . $next() . '1';
118
-            })->apply(function ($request, $response, $next) {
117
+                return '1'.$next().'1';
118
+            })->apply(function($request, $response, $next) {
119 119
 
120
-                return '2' . $next() . '2';
120
+                return '2'.$next().'2';
121 121
             });
122 122
             $route = $r->route('foo/bar');
123 123
             $actual = $route->dispatch();
124 124
             expect($actual)->toBe('21A12');
125 125
         });
126 126
     });
127
-    describe("->link()", function () {
127
+    describe("->link()", function() {
128 128
 
129 129
 
130
-        it("creates relative links", function () {
130
+        it("creates relative links", function() {
131 131
 
132 132
 
133 133
             $route = new Route(['pattern' => '/foo/{bar}']);
134 134
             $link = $route->link(['bar' => 'baz']);
135 135
             expect($link)->toBe('/foo/baz');
136 136
         });
137
-        it("supports optionnal parameters", function () {
137
+        it("supports optionnal parameters", function() {
138 138
 
139 139
 
140 140
             $route = new Route(['pattern' => '/foo[/{bar}]']);
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
             $link = $route->link(['bar' => 'baz']);
144 144
             expect($link)->toBe('/foo/baz');
145 145
         });
146
-        it("supports multiple optionnal parameters", function () {
146
+        it("supports multiple optionnal parameters", function() {
147 147
 
148 148
 
149 149
             $route = new Route(['pattern' => '/file[/{paths}]*']);
@@ -152,14 +152,14 @@  discard block
 block discarded – undo
152 152
             $link = $route->link(['paths' => ['some', 'file', 'path']]);
153 153
             expect($link)->toBe('/file/some/file/path');
154 154
         });
155
-        it("merges default params", function () {
155
+        it("merges default params", function() {
156 156
 
157 157
 
158 158
             $route = new Route(['pattern' => '/foo/{bar}', 'params' => ['bar' => 'baz']]);
159 159
             $link = $route->link();
160 160
             expect($link)->toBe('/foo/baz');
161 161
         });
162
-        it("creates absolute links with custom base path", function () {
162
+        it("creates absolute links with custom base path", function() {
163 163
 
164 164
 
165 165
             $route = new Route([
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
             ]);
177 177
             expect($link)->toBe('https://www.example.com/app/foo/baz');
178 178
         });
179
-        it("allows host and scheme overriding", function () {
179
+        it("allows host and scheme overriding", function() {
180 180
 
181 181
 
182 182
             $route = new Route([
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
             ]);
196 196
             expect($link)->toBe('http://www.overrided.com/app/foo/baz');
197 197
         });
198
-        it("supports repeatable parameter placeholders as an array", function () {
198
+        it("supports repeatable parameter placeholders as an array", function() {
199 199
 
200 200
 
201 201
             $route = new Route(['pattern' => 'post[/{id}]*']);
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
             expect($route->link(['id' => ['123']]))->toBe('/post/123');
208 208
             expect($route->link(['id' => ['123', '456', '789']]))->toBe('/post/123/456/789');
209 209
         });
210
-        it("supports route with multiple optional segments", function () {
210
+        it("supports route with multiple optional segments", function() {
211 211
 
212 212
 
213 213
             $route = new Route(['pattern' => '[{relation}/{rid:[^/:][^/]*}/]post[/{id:[^/:][^/]*}][/:{action}]']);
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
             $link = $route->link(['relation' => 'user', 'rid' => 5, 'action' => 'edit', 'id' => 12]);
223 223
             expect($link)->toBe('/user/5/post/12/:edit');
224 224
         });
225
-        it("supports route with complex repeatable optional segments", function () {
225
+        it("supports route with complex repeatable optional segments", function() {
226 226
 
227 227
 
228 228
             $route = new Route(['pattern' => '[{relations:[^/]+/[^/:][^/]*}/]*post[/{id:[^/:][^/]*}][/:{action}]']);
@@ -237,40 +237,40 @@  discard block
 block discarded – undo
237 237
             $link = $route->link(['relations' => [['user', 5]], 'action' => 'edit', 'id' => 12]);
238 238
             expect($link)->toBe('/user/5/post/12/:edit');
239 239
         });
240
-        it("throws an exception for missing variables", function () {
240
+        it("throws an exception for missing variables", function() {
241 241
 
242 242
 
243
-            $closure = function () {
243
+            $closure = function() {
244 244
 
245 245
                 $route = new Route(['pattern' => 'post[/{id}]+']);
246 246
                 echo $route->link([]);
247 247
             };
248 248
             expect($closure)->toThrow(new RouterException("Missing parameters `'id'` for route: `'#/post[/{id}]+'`."));
249 249
         });
250
-        it("throws an exception when a variable doesn't match its capture pattern", function () {
250
+        it("throws an exception when a variable doesn't match its capture pattern", function() {
251 251
 
252 252
 
253
-            $closure = function () {
253
+            $closure = function() {
254 254
 
255 255
                 $route = new Route(['pattern' => 'post/{id:[0-9]{3}}']);
256 256
                 $route->link(['id' => '1234']);
257 257
             };
258 258
             expect($closure)->toThrow(new RouterException("Expected `'id'` to match `'[0-9]{3}'`, but received `'1234'`."));
259 259
         });
260
-        it("throws an exception when a an array is provided for a non repeatable parameter placeholder", function () {
260
+        it("throws an exception when a an array is provided for a non repeatable parameter placeholder", function() {
261 261
 
262 262
 
263
-            $closure = function () {
263
+            $closure = function() {
264 264
 
265 265
                 $route = new Route(['pattern' => 'post/{id}']);
266 266
                 $route->link(['id' => ['123', '456']]);
267 267
             };
268 268
             expect($closure)->toThrow(new RouterException("Expected `'id'` to match `'[^/]+'`, but received `'123/456'`."));
269 269
         });
270
-        it("throws an exception when one element of an array doesn't match the capture pattern", function () {
270
+        it("throws an exception when one element of an array doesn't match the capture pattern", function() {
271 271
 
272 272
 
273
-            $closure = function () {
273
+            $closure = function() {
274 274
 
275 275
                 $route = new Route(['pattern' => 'post[/{id:[0-9]{3}}]+']);
276 276
                 $route->link(['id' => ['123', '456', '78']]);
@@ -278,17 +278,17 @@  discard block
 block discarded – undo
278 278
             expect($closure)->toThrow(new RouterException("Expected `'id'` to match `'[0-9]{3}'`, but received `'78'`."));
279 279
         });
280 280
     });
281
-    describe("->dispatch()", function () {
281
+    describe("->dispatch()", function() {
282 282
 
283 283
 
284
-        it("passes route as argument of the handler function", function () {
284
+        it("passes route as argument of the handler function", function() {
285 285
 
286 286
 
287 287
             $r = new Router();
288 288
             $r->get(
289 289
                 'foo/{var1}[/{var2}]',
290 290
                 ['host' => '{subdomain}.{domain}.bar'],
291
-                function ($route, $response) {
291
+                function($route, $response) {
292 292
 
293 293
                     return array_merge([$response], array_values($route->params));
294 294
                 }
@@ -301,13 +301,13 @@  discard block
 block discarded – undo
301 301
             $actual = $route->dispatch($response);
302 302
             expect($actual)->toBe([$response, 'foo', 'biz', '25', 'bar']);
303 303
         });
304
-        it("throws an exception on non valid routes", function () {
304
+        it("throws an exception on non valid routes", function() {
305 305
 
306 306
 
307
-            $closure = function () {
307
+            $closure = function() {
308 308
 
309 309
                 $r = new Router();
310
-                $r->get('foo', function () {
310
+                $r->get('foo', function() {
311 311
                 });
312 312
                 $route = $r->route('bar');
313 313
                 $route->dispatch();
Please login to merge, or discard this patch.
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.
src/Route.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         $this->setMethods($config['methods']);
181 181
         $this->setScope($config['scope']);
182 182
         $this->setPattern($config['pattern']);
183
-        $this->setMiddleware((array)$config['middleware']);
183
+        $this->setMiddleware((array) $config['middleware']);
184 184
     }
185 185
 
186 186
     /**
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      */
192 192
     public function setMiddleware(array $middleware)
193 193
     {
194
-        $this->middleware = (array)$middleware;
194
+        $this->middleware = (array) $middleware;
195 195
 
196 196
         return $this;
197 197
     }
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
     {
372 372
         $this->prefix = trim($prefix, '/');
373 373
         if ($this->prefix) {
374
-            $this->prefix = '/' . $this->prefix;
374
+            $this->prefix = '/'.$this->prefix;
375 375
         }
376 376
 
377 377
         return $this;
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
      */
441 441
     public function setMethods($methods): self
442 442
     {
443
-        $methods = $methods ? (array)$methods : [];
443
+        $methods = $methods ? (array) $methods : [];
444 444
         $methods = array_map('strtoupper', $methods);
445 445
         $methods = array_fill_keys($methods, true);
446 446
 
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
      */
464 464
     public function allow($methods = [])
465 465
     {
466
-        $methods = $methods ? (array)$methods : [];
466
+        $methods = $methods ? (array) $methods : [];
467 467
         $methods = array_map('strtoupper', $methods);
468 468
         $methods = array_fill_keys($methods, true) + $this->methods;
469 469
 
@@ -523,10 +523,10 @@  discard block
 block discarded – undo
523 523
         $this->variables = null;
524 524
 
525 525
         if (!$pattern || $pattern[0] !== '[') {
526
-            $pattern = '/' . trim($pattern, '/');
526
+            $pattern = '/'.trim($pattern, '/');
527 527
         }
528 528
 
529
-        $this->pattern = $this->prefix . $pattern;
529
+        $this->pattern = $this->prefix.$pattern;
530 530
 
531 531
         return $this;
532 532
     }
@@ -640,9 +640,9 @@  discard block
 block discarded – undo
640 640
             }
641 641
         }
642 642
 
643
-        $path = '/' . trim($path, '/');
643
+        $path = '/'.trim($path, '/');
644 644
 
645
-        if (!preg_match('~^' . $this->regex() . '$~', $path, $matches)) {
645
+        if (!preg_match('~^'.$this->regex().'$~', $path, $matches)) {
646 646
             return false;
647 647
         }
648 648
         $variables = $this->_buildVariables($matches);
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
             } else {
675 675
                 $token = $parser::tokenize($pattern, '/');
676 676
                 $rule = $parser::compile($token);
677
-                if (preg_match_all('~' . $rule[0] . '~', $values[$i], $parts)) {
677
+                if (preg_match_all('~'.$rule[0].'~', $values[$i], $parts)) {
678 678
                     foreach ($parts[1] as $value) {
679 679
                         if (strpos($value, '/') !== false) {
680 680
                             $variables[$name][] = explode('/', $value);
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
 
706 706
         $generator = $this->middleware();
707 707
 
708
-        $next = function () use ($request, $response, $generator, &$next) {
708
+        $next = function() use ($request, $response, $generator, &$next) {
709 709
             $handler = $generator->current();
710 710
             $generator->next();
711 711
 
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
             }
734 734
         }
735 735
 
736
-        yield function () {
736
+        yield function() {
737 737
             $handler = $this->handler();
738 738
             if ($handler === null) {
739 739
                 return null;
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
 
782 782
         $options = array_filter(
783 783
             $options,
784
-            function ($value) {
784
+            function($value) {
785 785
                 return $value !== '*';
786 786
             }
787 787
         );
@@ -793,24 +793,24 @@  discard block
 block discarded – undo
793 793
 
794 794
         $basePath = trim($options['basePath'], '/');
795 795
         if ($basePath) {
796
-            $basePath = '/' . $basePath;
796
+            $basePath = '/'.$basePath;
797 797
         }
798 798
         $link = isset($link) ? ltrim($link, '/') : '';
799
-        $link = $basePath . ($link ? '/' . $link : $link);
800
-        $query = $options['query'] ? '?' . $options['query'] : '';
801
-        $fragment = $options['fragment'] ? '#' . $options['fragment'] : '';
799
+        $link = $basePath.($link ? '/'.$link : $link);
800
+        $query = $options['query'] ? '?'.$options['query'] : '';
801
+        $fragment = $options['fragment'] ? '#'.$options['fragment'] : '';
802 802
 
803 803
         if ($options['absolute']) {
804 804
             if ($this->host !== null) {
805
-                $link = $this->host->link($params, $options) . "{$link}";
805
+                $link = $this->host->link($params, $options)."{$link}";
806 806
             } else {
807
-                $scheme = !empty($options['scheme']) ? $options['scheme'] . '://' : '//';
807
+                $scheme = !empty($options['scheme']) ? $options['scheme'].'://' : '//';
808 808
                 $host = isset($options['host']) ? $options['host'] : 'localhost';
809 809
                 $link = "{$scheme}{$host}{$link}";
810 810
             }
811 811
         }
812 812
 
813
-        return $link . $query . $fragment;
813
+        return $link.$query.$fragment;
814 814
     }
815 815
 
816 816
     /**
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
             if (isset($child['tokens'])) {
832 832
                 if ($child['repeat']) {
833 833
                     $name = $child['repeat'];
834
-                    $values = isset($params[$name]) && $params[$name] !== null ? (array)$params[$name] : [];
834
+                    $values = isset($params[$name]) && $params[$name] !== null ? (array) $params[$name] : [];
835 835
                     if (!$values && !$child['optional']) {
836 836
                         throw new RouterException("Missing parameters `'{$name}'` for route: `'{$this->name}#{$this->pattern}'`.");
837 837
                     }
@@ -858,12 +858,12 @@  discard block
 block discarded – undo
858 858
                 $parts = [];
859 859
             }
860 860
             foreach ($parts as $key => $value) {
861
-                $parts[$key] = rawurlencode((string)$value);
861
+                $parts[$key] = rawurlencode((string) $value);
862 862
             }
863 863
             $value = join('/', $parts);
864 864
 
865
-            if (!preg_match('~^' . $child['pattern'] . '$~', $value)) {
866
-                throw new RouterException("Expected `'" . $child['name'] . "'` to match `'" . $child['pattern'] . "'`, but received `'" . $value . "'`.");
865
+            if (!preg_match('~^'.$child['pattern'].'$~', $value)) {
866
+                throw new RouterException("Expected `'".$child['name']."'` to match `'".$child['pattern']."'`, but received `'".$value."'`.");
867 867
             }
868 868
             $link .= $value;
869 869
         }
Please login to merge, or discard this patch.
spec/Suite/Router.spec.php 1 patch
Spacing   +161 added lines, -161 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->basePath())->toBe('');
35 35
         });
36 36
     });
37
-    describe("->basePath()", function () {
37
+    describe("->basePath()", 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->basePath())->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->basePath())->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,42 +99,42 @@  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 trying to use the `'method'` option", function () {
114
+        it("throws an exception when trying to use the `'method'` option", function() {
115 115
 
116 116
 
117
-            $closure = function () {
117
+            $closure = function() {
118 118
 
119 119
                 $r = $this->router;
120
-                $r->bind('foo', ['method' => 'GET'], function () {
120
+                $r->bind('foo', ['method' => 'GET'], function() {
121 121
                 });
122 122
             };
123 123
             expect($closure)->toThrow(new RouterException("Use the `'methods'` option to limit HTTP verbs on a route binding definition."));
124 124
         });
125 125
     });
126
-    describe("->link()", function () {
126
+    describe("->link()", function() {
127 127
 
128 128
 
129
-        it("forwards router base path", function () {
129
+        it("forwards router base path", function() {
130 130
 
131 131
 
132 132
             $r = $this->router;
133 133
             $r->basePath('app');
134 134
 
135
-            $r->group(['host' => 'www.{domain}.com', 'scheme' => 'https'], function ($r) {
135
+            $r->group(['host' => 'www.{domain}.com', 'scheme' => 'https'], function($r) {
136 136
 
137
-                $r->bind('foo/{bar}', ['name' => 'foo'], function () {
137
+                $r->bind('foo/{bar}', ['name' => 'foo'], function() {
138 138
                 });
139 139
             });
140 140
             $link = $r->link('foo', [
@@ -143,28 +143,28 @@  discard block
 block discarded – undo
143 143
             ], ['absolute' => true]);
144 144
             expect($link)->toBe('https://www.example.com/app/foo/baz');
145 145
         });
146
-        it("maintains prefixes in nested routes", function () {
146
+        it("maintains prefixes in nested routes", function() {
147 147
 
148 148
 
149 149
             $r = $this->router;
150
-            $r->group('foo', ['name' => 'foz'], function ($r) {
150
+            $r->group('foo', ['name' => 'foz'], function($r) {
151 151
 
152
-                $r->group('bar', ['name' => 'baz'], function ($r) {
152
+                $r->group('bar', ['name' => 'baz'], function($r) {
153 153
 
154
-                    $r->bind('{var1}', ['name' => 'quz'], function () {
154
+                    $r->bind('{var1}', ['name' => 'quz'], function() {
155 155
                     });
156 156
                 });
157 157
             });
158 158
             $link = $r->link('foz.baz.quz', ['var1' => 'hello']);
159 159
             expect($link)->toBe('/foo/bar/hello');
160 160
         });
161
-        it("persists persisted parameters in a dispatching context", function () {
161
+        it("persists persisted parameters in a dispatching context", function() {
162 162
 
163 163
 
164 164
             $r = $this->router;
165
-            $r->group('{locale:en|fr}', ['persist' => 'locale'], function ($r) {
165
+            $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) {
166 166
 
167
-                $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function () {
167
+                $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function() {
168 168
                 });
169 169
             });
170 170
             $r->route('fr/post/index');
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
             ]);
183 183
             expect($link)->toBe('/en/post/view/5');
184 184
         });
185
-        it("overrides persisted parameters in a dispatching context", function () {
185
+        it("overrides persisted parameters in a dispatching context", function() {
186 186
 
187 187
 
188 188
             $r = $this->router;
189
-            $r->group('{locale:en|fr}', ['persist' => 'locale'], function ($r) {
189
+            $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) {
190 190
 
191
-                $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function () {
191
+                $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function() {
192 192
                 });
193 193
             });
194 194
             $r->route('fr/post/index');
@@ -200,24 +200,24 @@  discard block
 block discarded – undo
200 200
             ]);
201 201
             expect($link)->toBe('/en/post/view/5');
202 202
         });
203
-        it("throws an exception when no route is found for a specified name", function () {
203
+        it("throws an exception when no route is found for a specified name", function() {
204 204
 
205 205
 
206
-            $closure = function () {
206
+            $closure = function() {
207 207
 
208 208
                 $this->router->link('not.binded.yet', []);
209 209
             };
210 210
             expect($closure)->toThrow(new RouterException("No route defined for `'not.binded.yet'`, bind it first with `bind()`."));
211 211
         });
212 212
     });
213
-    describe("->route()", function () {
213
+    describe("->route()", function() {
214 214
 
215 215
 
216
-        it("routes on a simple route", function () {
216
+        it("routes on a simple route", function() {
217 217
 
218 218
 
219 219
             $r = $this->router;
220
-            $r->bind('foo/bar', function () {
220
+            $r->bind('foo/bar', function() {
221 221
             });
222 222
             $route = $r->route('foo/bar', 'GET');
223 223
             expect($this->export($route->request))->toEqual([
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`.");
233 233
             }
234 234
         });
235
-        it("routes on a named route", function () {
235
+        it("routes on a named route", function() {
236 236
 
237 237
 
238 238
             $r = $this->router;
239
-            $r->bind('foo/bar', ['name' => 'foo'], function () {
239
+            $r->bind('foo/bar', ['name' => 'foo'], function() {
240 240
             });
241 241
             $route = $r->route('foo/bar', 'GET');
242 242
             expect($route->name)->toBe('foo');
@@ -246,11 +246,11 @@  discard block
 block discarded – undo
246 246
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`.");
247 247
             }
248 248
         });
249
-        it("supports empty as index route", function () {
249
+        it("supports empty as index route", function() {
250 250
 
251 251
 
252 252
             $r = $this->router;
253
-            $r->bind('', function () {
253
+            $r->bind('', function() {
254 254
             });
255 255
             $route = $r->route('', 'GET');
256 256
             expect($this->export($route->request))->toEqual([
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
                 'path'   => ''
261 261
             ]);
262 262
         });
263
-        it("supports a slash as indes route", function () {
263
+        it("supports a slash as indes route", function() {
264 264
 
265 265
 
266 266
             $r = $this->router;
267
-            $r->bind('/', function () {
267
+            $r->bind('/', function() {
268 268
             });
269 269
             $route = $r->route('', 'GET');
270 270
             expect($this->export($route->request))->toEqual([
@@ -274,11 +274,11 @@  discard block
 block discarded – undo
274 274
                 'path'   => ''
275 275
             ]);
276 276
         });
277
-        it("supports route variables", function () {
277
+        it("supports route variables", function() {
278 278
 
279 279
 
280 280
             $r = $this->router;
281
-            $r->get('foo/{param}', function () {
281
+            $r->get('foo/{param}', function() {
282 282
             });
283 283
             $route = $r->route('foo/bar', 'GET');
284 284
             expect($route->params)->toBe(['param' => 'bar']);
@@ -288,11 +288,11 @@  discard block
 block discarded – undo
288 288
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`.");
289 289
             }
290 290
         });
291
-        it("supports constrained route variables", function () {
291
+        it("supports constrained route variables", function() {
292 292
 
293 293
 
294 294
             $r = $this->router;
295
-            $r->get('foo/{var1:\d+}', function () {
295
+            $r->get('foo/{var1:\d+}', function() {
296 296
             });
297 297
             $route = $r->route('foo/25', 'GET');
298 298
             expect($route->params)->toBe(['var1' => '25']);
@@ -302,22 +302,22 @@  discard block
 block discarded – undo
302 302
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/foo/bar`.");
303 303
             }
304 304
         });
305
-        it("supports optional segments with variables", function () {
305
+        it("supports optional segments with variables", function() {
306 306
 
307 307
 
308 308
             $r = $this->router;
309
-            $r->get('foo[/{var1}]', function () {
309
+            $r->get('foo[/{var1}]', function() {
310 310
             });
311 311
             $route = $r->route('foo', 'GET');
312 312
             expect($route->params)->toBe(['var1' => null]);
313 313
             $route = $r->route('foo/bar', 'GET');
314 314
             expect($route->params)->toBe(['var1' => 'bar']);
315 315
         });
316
-        it("supports repeatable segments", function () {
316
+        it("supports repeatable segments", function() {
317 317
 
318 318
 
319 319
             $r = $this->router;
320
-            $r->get('foo[/:{var1}]*[/bar[/:{var2}]*]', function () {
320
+            $r->get('foo[/:{var1}]*[/bar[/:{var2}]*]', function() {
321 321
             });
322 322
             $route = $r->route('foo', 'GET');
323 323
             expect($route->params)->toBe([
@@ -335,11 +335,11 @@  discard block
 block discarded – undo
335 335
                 'var2' => ['fuz']
336 336
             ]);
337 337
         });
338
-        it("supports optional segments with custom variable regex", function () {
338
+        it("supports optional segments with custom variable regex", function() {
339 339
 
340 340
 
341 341
             $r = $this->router;
342
-            $r->get('foo[/{var1:\d+}]', function () {
342
+            $r->get('foo[/{var1:\d+}]', function() {
343 343
             });
344 344
             $route = $r->route('foo', 'GET');
345 345
             expect($route->params)->toBe(['var1' => null]);
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
                 expect($e->getMessage())->toBe("No route found for `*:*:GET:/foo/baz`.");
352 352
             }
353 353
         });
354
-        it("supports multiple optional segments", function () {
354
+        it("supports multiple optional segments", function() {
355 355
 
356 356
 
357 357
             $patterns = [
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
             $r = $this->router;
361 361
 
362 362
             foreach ($patterns as $pattern) {
363
-                $r->get($pattern, function () {
363
+                $r->get($pattern, function() {
364 364
                 });
365 365
                 $route = $r->route('foo', 'GET');
366 366
                 expect($route->params)->toBe(['var1' => 'foo', 'var2' => null]);
@@ -369,13 +369,13 @@  discard block
 block discarded – undo
369 369
                 $r->clear();
370 370
             };
371 371
         });
372
-        it("supports host variables", function () {
372
+        it("supports host variables", function() {
373 373
 
374 374
 
375 375
             $r = $this->router;
376
-            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function () {
376
+            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function() {
377 377
             });
378
-            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function () {
378
+            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function() {
379 379
             });
380 380
             $route = $r->route('foo/25', 'GET', 'foo.biz.bar');
381 381
             expect($route->Host()->pattern())->toBe('foo.{domain}.bar');
@@ -384,27 +384,27 @@  discard block
 block discarded – undo
384 384
             expect($route->Host()->pattern())->toBe('foo.{domain}.baz');
385 385
             expect($route->params)->toBe(['domain' => 'buz', 'var1' => '50']);
386 386
         });
387
-        it("supports constrained host variables", function () {
387
+        it("supports constrained host variables", function() {
388 388
 
389 389
 
390 390
             $r = $this->router;
391
-            $r->get('foo/{var1:\d+}', ['host' => '{subdomain:foo}.{domain}.bar'], function () {
391
+            $r->get('foo/{var1:\d+}', ['host' => '{subdomain:foo}.{domain}.bar'], function() {
392 392
             });
393 393
             $route = $r->route('foo/25', 'GET', 'foo.biz.bar');
394
-            expect($route->params)->toBe([ 'subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']);
394
+            expect($route->params)->toBe(['subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']);
395 395
             try {
396 396
                 $route = $r->route('foo/bar', 'GET', 'foo.biz.bar');
397 397
             } catch (RouteNotFoundException $e) {
398 398
                 expect($e->getMessage())->toBe("No route found for `*:foo.biz.bar:GET:/foo/bar`.");
399 399
             }
400 400
         });
401
-        it("supports absolute URL", function () {
401
+        it("supports absolute URL", function() {
402 402
 
403 403
 
404 404
             $r = $this->router;
405
-            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function () {
405
+            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function() {
406 406
             });
407
-            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function () {
407
+            $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function() {
408 408
             });
409 409
             $route = $r->route('http://foo.biz.bar/foo/25', 'GET');
410 410
             expect($route->Host()->pattern())->toBe('foo.{domain}.bar');
@@ -413,23 +413,23 @@  discard block
 block discarded – undo
413 413
             expect($route->Host()->pattern())->toBe('foo.{domain}.baz');
414 414
             expect($route->params)->toBe(['domain' => 'buz', 'var1' => '50']);
415 415
         });
416
-        it("supports RESTful routes", function () {
416
+        it("supports RESTful routes", function() {
417 417
 
418 418
 
419 419
             $r = $this->router;
420
-            $r->get('foo/bar', function () {
420
+            $r->get('foo/bar', function() {
421 421
             });
422
-            $r->head('foo/bar', function () {
422
+            $r->head('foo/bar', function() {
423 423
             });
424
-            $r->post('foo/bar', function () {
424
+            $r->post('foo/bar', function() {
425 425
             });
426
-            $r->put('foo/bar', function () {
426
+            $r->put('foo/bar', function() {
427 427
             });
428
-            $r->patch('foo/bar', function () {
428
+            $r->patch('foo/bar', function() {
429 429
             });
430
-            $r->delete('foo/bar', function () {
430
+            $r->delete('foo/bar', function() {
431 431
             });
432
-            $r->options('foo/bar', function () {
432
+            $r->options('foo/bar', function() {
433 433
             });
434 434
             $methods = ['OPTIONS', 'DELETE', 'PATCH', 'PUT', 'POST', 'HEAD', 'GET'];
435 435
             $route = $r->route('foo/bar', 'GET');
@@ -447,11 +447,11 @@  discard block
 block discarded – undo
447 447
             $route = $r->route('foo/bar', 'OPTIONS');
448 448
             expect($route->Methods())->toBe($methods);
449 449
         });
450
-        it("matches relationships based routes", function () {
450
+        it("matches relationships based routes", function() {
451 451
 
452 452
 
453 453
             $r = $this->router;
454
-            $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function () {
454
+            $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function() {
455 455
             });
456 456
             $route = $r->route('blog/1/post/22/comment/:show', 'GET');
457 457
             expect($route->params)->toBe([
@@ -463,35 +463,35 @@  discard block
 block discarded – undo
463 463
                 'action' => 'show'
464 464
             ]);
465 465
         });
466
-        it("dispatches HEAD requests on matching GET routes if the HEAD routes are missing", function () {
466
+        it("dispatches HEAD requests on matching GET routes if the HEAD routes are missing", function() {
467 467
 
468 468
 
469 469
             $r = $this->router;
470
-            $r->get('foo/bar', function () {
470
+            $r->get('foo/bar', function() {
471 471
                 return 'GET';
472 472
             });
473 473
             $route = $r->route('foo/bar', 'HEAD');
474 474
             expect($route->Methods())->toBe(['GET']);
475 475
         });
476
-        it("dispatches HEAD requests on matching HEAD routes", function () {
476
+        it("dispatches HEAD requests on matching HEAD routes", function() {
477 477
 
478 478
 
479 479
             $r = $this->router;
480 480
 
481
-            $r->head('foo/bar', function () {
481
+            $r->head('foo/bar', function() {
482 482
                 return 'HEAD';
483 483
             });
484
-            $r->get('foo/bar', function () {
484
+            $r->get('foo/bar', function() {
485 485
                 return 'GET';
486 486
             });
487 487
             $route = $r->route('foo/bar', 'HEAD');
488 488
             expect($route->Methods())->toBe(['GET', 'HEAD']);
489 489
         });
490
-        it("supports requests as a list of arguments", function () {
490
+        it("supports requests as a list of arguments", function() {
491 491
 
492 492
 
493 493
             $r = $this->router;
494
-            $r->bind('foo/bar', function () {
494
+            $r->bind('foo/bar', function() {
495 495
             });
496 496
             $route = $r->route('foo/bar', 'GET');
497 497
             expect($this->export($route->request))->toEqual([
@@ -501,10 +501,10 @@  discard block
 block discarded – undo
501 501
                 'path'   => 'foo/bar'
502 502
             ]);
503 503
         });
504
-        it("supports requests as an object", function () {
504
+        it("supports requests as an object", function() {
505 505
 
506 506
             $r = $this->router;
507
-            $r->bind('foo/bar', function () {
507
+            $r->bind('foo/bar', function() {
508 508
             });
509 509
             $request = Double::instance(['implements' => ServerRequestInterface::class]);
510 510
             $uri = Double::instance(['implements' => UriInterface::class]);
@@ -517,11 +517,11 @@  discard block
 block discarded – undo
517 517
             $route = $r->route($request, 'GET');
518 518
             expect($route->request)->toBe($request);
519 519
         });
520
-        it("supports requests as an array", function () {
520
+        it("supports requests as an array", function() {
521 521
 
522 522
 
523 523
             $r = $this->router;
524
-            $r->bind('foo/bar', function () {
524
+            $r->bind('foo/bar', function() {
525 525
             });
526 526
             $route = $r->route(['path' => 'foo/bar'], 'GET');
527 527
             expect($this->export($route->request))->toEqual([
@@ -532,59 +532,59 @@  discard block
 block discarded – undo
532 532
             ]);
533 533
         });
534 534
     });
535
-    describe("->group()", function () {
535
+    describe("->group()", function() {
536 536
 
537 537
 
538
-        it("supports nested named route", function () {
538
+        it("supports nested named route", function() {
539 539
 
540 540
 
541 541
             $r = $this->router;
542
-            $r->group('foo', ['name' => 'foz'], function ($r) use (&$route) {
542
+            $r->group('foo', ['name' => 'foz'], function($r) use (&$route) {
543 543
 
544
-                $r->group('bar', ['name' => 'baz'], function ($r) use (&$route) {
544
+                $r->group('bar', ['name' => 'baz'], function($r) use (&$route) {
545 545
 
546
-                    $route = $r->bind('{var1}', ['name' => 'quz'], function () {
546
+                    $route = $r->bind('{var1}', ['name' => 'quz'], function() {
547 547
                     });
548 548
                 });
549 549
             });
550 550
             expect(isset($r['foz.baz.quz']))->toBe(true);
551 551
             expect($r['foz.baz.quz'])->toBe($route);
552 552
         });
553
-        it("returns a working scope", function () {
553
+        it("returns a working scope", function() {
554 554
 
555 555
 
556 556
             $r = $this->router;
557
-            $route = $r->group('foo', ['name' => 'foz'], function () {
558
-            })->group('bar', ['name' => 'baz'], function () {
559
-            })->bind('{var1}', ['name' => 'quz'], function () {
557
+            $route = $r->group('foo', ['name' => 'foz'], function() {
558
+            })->group('bar', ['name' => 'baz'], function() {
559
+            })->bind('{var1}', ['name' => 'quz'], function() {
560 560
             });
561 561
             expect(isset($r['foz.baz.quz']))->toBe(true);
562 562
             expect($r['foz.baz.quz'])->toBe($route);
563 563
         });
564
-        context("with a prefix contraint", function () {
564
+        context("with a prefix contraint", function() {
565 565
 
566 566
 
567
-            beforeEach(function () {
567
+            beforeEach(function() {
568 568
 
569 569
 
570 570
                 $r = $this->router;
571
-                $r->group('foo', function ($r) {
571
+                $r->group('foo', function($r) {
572 572
 
573
-                    $r->bind('{var1}', function () {
573
+                    $r->bind('{var1}', function() {
574 574
                     });
575 575
                 });
576 576
             });
577
-            it("respects url's prefix constraint", function () {
577
+            it("respects url's prefix constraint", function() {
578 578
 
579 579
 
580 580
                 $r = $this->router;
581 581
                 $route = $r->route('foo/bar');
582 582
                 expect($route->params)->toBe(['var1'   => 'bar']);
583 583
             });
584
-            it("throws an exception when the prefix does not match", function () {
584
+            it("throws an exception when the prefix does not match", function() {
585 585
 
586 586
 
587
-                $closure = function () {
587
+                $closure = function() {
588 588
 
589 589
                     $r = $this->router;
590 590
                     $route = $r->route('bar/foo', 'GET');
@@ -592,30 +592,30 @@  discard block
 block discarded – undo
592 592
                 expect($closure)->toThrow(new RouteNotFoundException("No route found for `*:*:GET:/bar/foo`."));
593 593
             });
594 594
         });
595
-        context("with a prefix contraint and an optional parameter", function () {
595
+        context("with a prefix contraint and an optional parameter", function() {
596 596
 
597 597
 
598
-            beforeEach(function () {
598
+            beforeEach(function() {
599 599
 
600 600
 
601 601
                 $r = $this->router;
602
-                $r->group('foo', function ($r) {
602
+                $r->group('foo', function($r) {
603 603
 
604
-                    $r->bind('[{var1}]', function () {
604
+                    $r->bind('[{var1}]', function() {
605 605
                     });
606 606
                 });
607 607
             });
608
-            it("respects url's prefix constraint", function () {
608
+            it("respects url's prefix constraint", function() {
609 609
 
610 610
 
611 611
                 $r = $this->router;
612 612
                 $route = $r->route('foo');
613 613
                 expect($route->params)->toBe(['var1' => null]);
614 614
             });
615
-            it("throws an exception when the prefix does not match", function () {
615
+            it("throws an exception when the prefix does not match", function() {
616 616
 
617 617
 
618
-                $closure = function () {
618
+                $closure = function() {
619 619
 
620 620
                     $r = $this->router;
621 621
                     $route = $r->route('bar/foo', 'GET');
@@ -623,23 +623,23 @@  discard block
 block discarded – undo
623 623
                 expect($closure)->toThrow(new RouteNotFoundException("No route found for `*:*:GET:/bar/foo`."));
624 624
             });
625 625
         });
626
-        context("with a host constraint", function () {
626
+        context("with a host constraint", function() {
627 627
 
628 628
 
629
-            beforeEach(function () {
629
+            beforeEach(function() {
630 630
 
631 631
 
632 632
                 $r = $this->router;
633
-                $r->group('foo', ['host' => 'foo.{domain}.bar'], function ($r) {
633
+                $r->group('foo', ['host' => 'foo.{domain}.bar'], function($r) {
634 634
 
635
-                    $r->group('bar', function ($r) {
635
+                    $r->group('bar', function($r) {
636 636
 
637
-                        $r->bind('{var1}', function () {
637
+                        $r->bind('{var1}', function() {
638 638
                         });
639 639
                     });
640 640
                 });
641 641
             });
642
-            it("respects url's host constraint", function () {
642
+            it("respects url's host constraint", function() {
643 643
 
644 644
 
645 645
                 $r = $this->router;
@@ -649,10 +649,10 @@  discard block
 block discarded – undo
649 649
                     'var1'   => 'baz'
650 650
                 ]);
651 651
             });
652
-            it("throws an exception when the host does not match", function () {
652
+            it("throws an exception when the host does not match", function() {
653 653
 
654 654
 
655
-                $closure = function () {
655
+                $closure = function() {
656 656
 
657 657
                     $r = $this->router;
658 658
                     $route = $r->route('http://bar.hello.foo/foo/bar/baz', 'GET');
@@ -660,23 +660,23 @@  discard block
 block discarded – undo
660 660
                 expect($closure)->toThrow(new RouteNotFoundException("No route found for `http:bar.hello.foo:GET:/foo/bar/baz`."));
661 661
             });
662 662
         });
663
-        context("with a scheme constraint", function () {
663
+        context("with a scheme constraint", function() {
664 664
 
665 665
 
666
-            beforeEach(function () {
666
+            beforeEach(function() {
667 667
 
668 668
 
669 669
                 $r = $this->router;
670
-                $r->group('foo', ['scheme' => 'http'], function ($r) {
670
+                $r->group('foo', ['scheme' => 'http'], function($r) {
671 671
 
672
-                    $r->group('bar', function ($r) {
672
+                    $r->group('bar', function($r) {
673 673
 
674
-                        $r->bind('{var1}', function () {
674
+                        $r->bind('{var1}', function() {
675 675
                         });
676 676
                     });
677 677
                 });
678 678
             });
679
-            it("respects url's scheme constraint", function () {
679
+            it("respects url's scheme constraint", function() {
680 680
 
681 681
 
682 682
                 $r = $this->router;
@@ -685,10 +685,10 @@  discard block
 block discarded – undo
685 685
                     'var1'   => 'baz'
686 686
                 ]);
687 687
             });
688
-            it("throws an exception when route is not found", function () {
688
+            it("throws an exception when route is not found", function() {
689 689
 
690 690
 
691
-                $closure = function () {
691
+                $closure = function() {
692 692
 
693 693
                     $r = $this->router;
694 694
                     $route = $r->route('https://domain.com/foo/bar/baz', 'GET');
@@ -696,25 +696,25 @@  discard block
 block discarded – undo
696 696
                 expect($closure)->toThrow(new RouteNotFoundException("No route found for `https:domain.com:GET:/foo/bar/baz`."));
697 697
             });
698 698
         });
699
-        it("concats namespace values", function () {
699
+        it("concats namespace values", function() {
700 700
 
701 701
 
702 702
             $r = $this->router;
703
-            $r->group('foo', ['namespace' => 'My'], function ($r) {
703
+            $r->group('foo', ['namespace' => 'My'], function($r) {
704 704
 
705
-                $r->group('bar', ['namespace' => 'Name'], function ($r) {
705
+                $r->group('bar', ['namespace' => 'Name'], function($r) {
706 706
 
707
-                    $r->bind('{var1}', ['namespace' => 'Space'], function () {
707
+                    $r->bind('{var1}', ['namespace' => 'Space'], function() {
708 708
                     });
709 709
                 });
710 710
             });
711 711
             $route = $r->route('foo/bar/baz', 'GET');
712 712
             expect($route->namespace)->toBe('My\Name\Space\\');
713 713
         });
714
-        it("throws an exception when the handler is not a closure", function () {
714
+        it("throws an exception when the handler is not a closure", function() {
715 715
 
716 716
 
717
-            $closure = function () {
717
+            $closure = function() {
718 718
 
719 719
                 $r = $this->router;
720 720
                 $r->group('foo', 'substr');
@@ -722,24 +722,24 @@  discard block
 block discarded – undo
722 722
             expect($closure)->toThrow(new RouterException("The handler needs to be an instance of `Closure` or implements the `__invoke()` magic method."));
723 723
         });
724 724
     });
725
-    describe("->middleware()", function () {
725
+    describe("->middleware()", function() {
726 726
 
727 727
 
728
-        it("returns global middleware", function () {
728
+        it("returns global middleware", function() {
729 729
 
730 730
 
731 731
             $r = $this->router;
732
-            $mw1 = function ($request, $response, $next) {
732
+            $mw1 = function($request, $response, $next) {
733 733
 
734
-                return '1' . $next() . '1';
734
+                return '1'.$next().'1';
735 735
             };
736
-            $mw2 = function ($request, $response, $next) {
736
+            $mw2 = function($request, $response, $next) {
737 737
 
738
-                return '2' . $next() . '2';
738
+                return '2'.$next().'2';
739 739
             };
740 740
             $r->apply($mw1, $mw2);
741 741
 
742
-            $next = function () {
742
+            $next = function() {
743 743
                 return '';
744 744
             };
745 745
             $generator = $r->middleware();
@@ -750,21 +750,21 @@  discard block
 block discarded – undo
750 750
             expect($actual1(null, null, $next))->toBe('11');
751 751
         });
752 752
     });
753
-    describe("->apply()", function () {
753
+    describe("->apply()", function() {
754 754
 
755 755
 
756
-        it("applies middlewares globally", function () {
756
+        it("applies middlewares globally", function() {
757 757
 
758 758
 
759 759
             $r = $this->router;
760
-            $r->apply(function ($request, $response, $next) {
760
+            $r->apply(function($request, $response, $next) {
761 761
 
762
-                return '1' . $next() . '1';
763
-            })->apply(function ($request, $response, $next) {
762
+                return '1'.$next().'1';
763
+            })->apply(function($request, $response, $next) {
764 764
 
765
-                return '2' . $next() . '2';
765
+                return '2'.$next().'2';
766 766
             });
767
-            $route = $r->bind('/foo/bar', function ($route) {
767
+            $route = $r->bind('/foo/bar', function($route) {
768 768
 
769 769
                 return 'A';
770 770
             });
@@ -772,27 +772,27 @@  discard block
 block discarded – undo
772 772
             $actual = $route->dispatch();
773 773
             expect($actual)->toBe('21A12');
774 774
         });
775
-        it("applies middlewares globally and per groups", function () {
775
+        it("applies middlewares globally and per groups", function() {
776 776
 
777 777
 
778 778
             $r = $this->router;
779
-            $r->apply(function ($request, $response, $next) {
779
+            $r->apply(function($request, $response, $next) {
780 780
 
781
-                return '1' . $next() . '1';
781
+                return '1'.$next().'1';
782 782
             });
783
-            $r->bind('foo/{foo}', ['name' => 'foo'], function () {
783
+            $r->bind('foo/{foo}', ['name' => 'foo'], function() {
784 784
 
785 785
                 return 'A';
786 786
             });
787
-            $r->group('bar', function ($r) {
787
+            $r->group('bar', function($r) {
788 788
 
789
-                $r->bind('{bar}', ['name' => 'bar'], function () {
789
+                $r->bind('{bar}', ['name' => 'bar'], function() {
790 790
 
791 791
                     return 'A';
792 792
                 });
793
-            })->apply(function ($request, $response, $next) {
793
+            })->apply(function($request, $response, $next) {
794 794
 
795
-                return '2' . $next() . '2';
795
+                return '2'.$next().'2';
796 796
             });
797 797
             $route = $r->route('foo/foo');
798 798
             $actual = $route->dispatch();
@@ -802,15 +802,15 @@  discard block
 block discarded – undo
802 802
             expect($actual)->toBe('21A12');
803 803
         });
804 804
     });
805
-    describe("->strategy()", function () {
805
+    describe("->strategy()", function() {
806 806
 
807 807
 
808
-        it("sets a strategy", function () {
808
+        it("sets a strategy", function() {
809 809
 
810 810
             $r = $this->router;
811
-            $mystrategy = function ($router) {
811
+            $mystrategy = function($router) {
812 812
 
813
-                $router->bind('foo/bar', function () {
813
+                $router->bind('foo/bar', function() {
814 814
 
815 815
                     return 'Hello World!';
816 816
                 });
@@ -821,11 +821,11 @@  discard block
 block discarded – undo
821 821
             $route = $r->route('foo/bar');
822 822
             expect($route->Pattern())->toBe('/foo/bar');
823 823
         });
824
-        it("unsets a strategy", function () {
824
+        it("unsets a strategy", function() {
825 825
 
826 826
             $r = $this->router;
827 827
 
828
-            $mystrategy = function () {
828
+            $mystrategy = function() {
829 829
             };
830 830
             $r->setStrategy('mystrategy', $mystrategy);
831 831
             expect($r->strategy('mystrategy'))->toBe($mystrategy);
Please login to merge, or discard this patch.
spec/Suite/Host.spec.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
 use Lead\Router\Exception\RouterException;
8 8
 use Lead\Router\Host;
9 9
 
10
-describe("Host", function () {
10
+describe("Host", function() {
11 11
 
12 12
 
13
-    describe("->scheme()", function () {
13
+    describe("->scheme()", function() {
14 14
 
15 15
 
16
-        it("gets/sets the scheme", function () {
16
+        it("gets/sets the scheme", function() {
17 17
 
18 18
 
19 19
             $host = new Host();
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
             expect($host->scheme())->toBe('https');
23 23
         });
24 24
     });
25
-    describe("->pattern()", function () {
25
+    describe("->pattern()", function() {
26 26
 
27 27
 
28
-        it("gets/sets the pattern", function () {
28
+        it("gets/sets the pattern", function() {
29 29
 
30 30
 
31 31
             $host = new Host();
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
                 'domain'    => false
38 38
             ]);
39 39
         });
40
-        it("updates the regex", function () {
40
+        it("updates the regex", function() {
41 41
 
42 42
 
43 43
             $host = new Host();
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             expect($host->setPattern('foo.{domain}.baz'))->toBe($host);
47 47
             expect($host->regex())->toBe('foo\\.([^.]+)\\.baz');
48 48
         });
49
-        it("updates the variables", function () {
49
+        it("updates the variables", function() {
50 50
 
51 51
 
52 52
             $host = new Host();
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
             ]);
61 61
         });
62 62
     });
63
-    describe("->match()", function () {
63
+    describe("->match()", function() {
64 64
 
65 65
 
66
-        it("returns `true` when host & scheme matches", function () {
66
+        it("returns `true` when host & scheme matches", function() {
67 67
 
68 68
 
69 69
             $host = new Host(['pattern' => 'foo.{domain}.bar', 'scheme' => 'https']);
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
             expect($host->match(['scheme' => 'https', 'host' => 'biz.bar.baz'], $variables))->toBe(false);
73 73
             expect($host->match(['scheme' => 'http', 'host' => 'foo.baz.bar'], $variables))->toBe(false);
74 74
         });
75
-        it("returns `true` when host matches with a wildcard as host's scheme", function () {
75
+        it("returns `true` when host matches with a wildcard as host's scheme", function() {
76 76
 
77 77
 
78 78
             $host = new Host(['pattern' => 'foo.{domain}.bar', 'scheme' => 'https']);
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
             expect($variables)->toBe(['domain' => 'baz']);
81 81
             expect($host->match(['scheme' => '*', 'host' => 'biz.baz.bar'], $variables))->toBe(false);
82 82
         });
83
-        it("returns `true` when host matches with a wildcard as request's scheme", function () {
83
+        it("returns `true` when host matches with a wildcard as request's scheme", function() {
84 84
 
85 85
 
86 86
             $host = new Host(['pattern' => 'foo.{domain}.bar', 'scheme' => '*']);
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
             expect($variables)->toBe(['domain' => 'baz']);
89 89
             expect($host->match(['scheme' => 'https', 'host' => 'biz.baz.bar'], $variables))->toBe(false);
90 90
         });
91
-        it("returns `true` when scheme matches with a wildcard as host's pattern", function () {
91
+        it("returns `true` when scheme matches with a wildcard as host's pattern", function() {
92 92
 
93 93
 
94 94
             $host = new Host(['pattern' => '*', 'scheme' => 'http']);
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             expect($variables)->toBe([]);
97 97
             expect($host->match(['scheme' => 'https', 'host' => 'foo.baz.bar'], $variables))->toBe(false);
98 98
         });
99
-        it("returns `true` when scheme matches with a wildcard as request's pattern", function () {
99
+        it("returns `true` when scheme matches with a wildcard as request's pattern", function() {
100 100
 
101 101
 
102 102
             $host = new Host(['pattern' => 'foo.{domain}.bar', 'scheme' => 'http']);
@@ -105,24 +105,24 @@  discard block
 block discarded – undo
105 105
             expect($host->match(['scheme' => 'https', 'host' => '*'], $variables))->toBe(false);
106 106
         });
107 107
     });
108
-    describe("->link()", function () {
108
+    describe("->link()", function() {
109 109
 
110 110
 
111
-        it("builds an host link", function () {
111
+        it("builds an host link", function() {
112 112
 
113 113
 
114 114
             $host = new Host(['pattern' => 'www.{domain}.com', 'scheme' => 'https']);
115 115
             $link = $host->link(['domain' => 'example']);
116 116
             expect($link)->toBe('https://www.example.com');
117 117
         });
118
-        it("builds a scheme less host link", function () {
118
+        it("builds a scheme less host link", function() {
119 119
 
120 120
 
121 121
             $host = new Host(['pattern' => 'www.{domain}.com']);
122 122
             $link = $host->link(['domain' => 'example']);
123 123
             expect($link)->toBe('//www.example.com');
124 124
         });
125
-        it("overrides scheme when passed as parameter", function () {
125
+        it("overrides scheme when passed as parameter", function() {
126 126
 
127 127
 
128 128
             $host = new Host(['pattern' => 'www.{domain}.com']);
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             ]);
132 132
             expect($link)->toBe('http://www.example.com');
133 133
         });
134
-        it("processes complex pattern", function () {
134
+        it("processes complex pattern", function() {
135 135
 
136 136
 
137 137
             $host = new Host(['pattern' => '[{subdomains}.]*{domain}.com', 'scheme' => 'https']);
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
                 'domain' => 'example'
146 146
             ]))->toBe('https://a.b.c.example.com');
147 147
         });
148
-        it("throws an exception when variables are missing", function () {
148
+        it("throws an exception when variables are missing", function() {
149 149
 
150 150
 
151
-            $closure = function () {
151
+            $closure = function() {
152 152
 
153 153
                 $host = new Host(['pattern' => 'www.{domain}.com']);
154 154
                 $link = $host->link();
Please login to merge, or discard this patch.