@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(strict_types = 1); |
|
2 | +declare(strict_types=1); |
|
3 | 3 | namespace Mezon\Router; |
4 | 4 | |
5 | 5 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getParam(string $name) |
52 | 52 | { |
53 | - if (! isset($this->getParameters()[$name])) { |
|
53 | + if (!isset($this->getParameters()[$name])) { |
|
54 | 54 | throw (new \Exception('Parameter ' . $name . ' was not found in route', - 1)); |
55 | 55 | } |
56 | 56 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(strict_types = 1); |
|
2 | +declare(strict_types=1); |
|
3 | 3 | namespace Mezon\Router; |
4 | 4 | |
5 | 5 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | { |
181 | 181 | $routerTrimmed = trim($router, '/'); |
182 | 182 | |
183 | - if (! isset($this->middleware[$routerTrimmed])) { |
|
183 | + if (!isset($this->middleware[$routerTrimmed])) { |
|
184 | 184 | $this->middleware[$routerTrimmed] = []; |
185 | 185 | } |
186 | 186 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(strict_types = 1); |
|
2 | +declare(strict_types=1); |
|
3 | 3 | namespace Mezon\Router; |
4 | 4 | |
5 | 5 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | { |
34 | 34 | $return = ''; |
35 | 35 | |
36 | - for ($n = 0; $n <= $i; $n ++) { |
|
36 | + for ($n = 0; $n <= $i; $n++) { |
|
37 | 37 | $return .= '()'; |
38 | 38 | } |
39 | 39 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | private function compileRegexpForBunch(array &$bunch): void |
49 | 49 | { |
50 | - if (! empty($bunch['bunch'])) { |
|
50 | + if (!empty($bunch['bunch'])) { |
|
51 | 51 | $bunch['regexp'] = ''; |
52 | 52 | /** @var array<int, array{pattern: string}> $hashTable */ |
53 | 53 | $hashTable = []; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | private function compileRegexpForBunches(): void |
88 | 88 | { |
89 | - if (! $this->regExpsWereCompiled) { |
|
89 | + if (!$this->regExpsWereCompiled) { |
|
90 | 90 | foreach (SupportedRequestMethods::getListOfSupportedRequestMethods() as $requestMethod) { |
91 | 91 | foreach ($this->paramRoutes[$requestMethod] as &$bunch) { |
92 | 92 | $this->compileRegexpForBunch($bunch); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $this->paramRoutes[$requestMethod][] = [ |
127 | 127 | 'bunch' => [] |
128 | 128 | ]; |
129 | - $bunchCursor ++; |
|
129 | + $bunchCursor++; |
|
130 | 130 | $lastBunchSize = 0; |
131 | 131 | } |
132 | 132 | |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | ]; |
221 | 221 | // TODO try to remove $hasRoutes flag |
222 | 222 | $hasRoutes = false; |
223 | - if (! empty($this->staticRoutes[$requestMethod])) { |
|
223 | + if (!empty($this->staticRoutes[$requestMethod])) { |
|
224 | 224 | $trace[] = implode(', ', array_keys($this->staticRoutes[$requestMethod])); |
225 | 225 | $trace[] = ', '; |
226 | 226 | $hasRoutes = true; |
227 | 227 | } |
228 | - if (! empty($this->paramRoutes[$requestMethod])) { |
|
228 | + if (!empty($this->paramRoutes[$requestMethod])) { |
|
229 | 229 | foreach ($this->paramRoutes[$requestMethod] as $bunch) { |
230 | 230 | $items = []; |
231 | 231 | foreach ($bunch['bunch'] as $item) { |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - if (! $hasRoutes) { |
|
239 | + if (!$hasRoutes) { |
|
240 | 240 | $trace[] = '<none>'; |
241 | 241 | } |
242 | 242 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(strict_types = 1); |
|
2 | +declare(strict_types=1); |
|
3 | 3 | namespace Mezon\Router; |
4 | 4 | |
5 | 5 | /** |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | $methodName[0] = strtolower($methodName[0]); |
33 | 33 | } |
34 | 34 | |
35 | - for ($i = 1; $i < strlen($methodName); $i ++) { |
|
35 | + for ($i = 1; $i < strlen($methodName); $i++) { |
|
36 | 36 | if (ctype_upper($methodName[$i])) { |
37 | 37 | $methodName = substr_replace($methodName, '-' . strtolower($methodName[$i]), $i, 1); |
38 | 38 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | public static function prepareRoute($route): string |
53 | 53 | { |
54 | 54 | if (is_array($route) && $route[0] === '') { |
55 | - $route = (string)$_SERVER['REQUEST_URI']; |
|
55 | + $route = (string) $_SERVER['REQUEST_URI']; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | if ($route === '/') { |
@@ -151,11 +151,11 @@ |
||
151 | 151 | return $id; |
152 | 152 | }); |
153 | 153 | $router->registerMiddleware('*', /** |
154 | - * |
|
155 | - * @psalm-param string $route |
|
156 | - * route |
|
157 | - * @psalm-param int $id parameter |
|
158 | - */ |
|
154 | + * |
|
155 | + * @psalm-param string $route |
|
156 | + * route |
|
157 | + * @psalm-param int $id parameter |
|
158 | + */ |
|
159 | 159 | function (string $route, int $id): int { |
160 | 160 | return $id; |
161 | 161 | }); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(strict_types = 1); |
|
2 | +declare(strict_types=1); |
|
3 | 3 | namespace Mezon\Router\Tests\Base; |
4 | 4 | |
5 | 5 | use PHPUnit\Framework\TestCase; |
@@ -30,19 +30,19 @@ discard block |
||
30 | 30 | // setup |
31 | 31 | $route = '/route-with-middleware/'; |
32 | 32 | $router = $this->getRouter(); |
33 | - $router->registerMiddleware('*', function () { |
|
33 | + $router->registerMiddleware('*', function() { |
|
34 | 34 | return [ |
35 | 35 | 1, |
36 | 36 | 2 |
37 | 37 | ]; |
38 | 38 | }); |
39 | - $router->addRoute($route, function (int $i, int $j) { |
|
39 | + $router->addRoute($route, function(int $i, int $j) { |
|
40 | 40 | return [ |
41 | 41 | $i, |
42 | 42 | $j |
43 | 43 | ]; |
44 | 44 | }); |
45 | - $router->registerMiddleware($route, function (int $i, int $j) { |
|
45 | + $router->registerMiddleware($route, function(int $i, int $j) { |
|
46 | 46 | return [ |
47 | 47 | $i, |
48 | 48 | $j |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $route = '/route/[i:id]'; |
68 | 68 | $router = $this->getRouter(); |
69 | 69 | |
70 | - $router->addRoute($route, function (string $route, array $parameters): array { |
|
70 | + $router->addRoute($route, function(string $route, array $parameters): array { |
|
71 | 71 | return $parameters; |
72 | 72 | }); |
73 | 73 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @psalm-param string $route route |
77 | 77 | * @psalm-param array{id: int} $parameters parameters |
78 | 78 | */ |
79 | - function (string $route, array $parameters): array { |
|
79 | + function(string $route, array $parameters): array { |
|
80 | 80 | $parameters['_second'] = $parameters['id']; |
81 | 81 | $parameters['id'] += 9; |
82 | 82 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | }); |
88 | 88 | |
89 | 89 | // This middleware is broken, don't parse the result |
90 | - $router->registerMiddleware($route, function (string $route, array $parameters) { |
|
90 | + $router->registerMiddleware($route, function(string $route, array $parameters) { |
|
91 | 91 | $parameters['_dont_set_this'] = true; |
92 | 92 | |
93 | 93 | return null; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * route |
100 | 100 | * @psalm-param array{id: int} $parameters parameters |
101 | 101 | */ |
102 | - function (string $route, array $parameters): array { |
|
102 | + function(string $route, array $parameters): array { |
|
103 | 103 | $parameters['_third'] = $parameters['id']; |
104 | 104 | $parameters['id'] *= 2; |
105 | 105 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * route |
116 | 116 | * @psalm-param int $id parameter |
117 | 117 | */ |
118 | - function (string $route, int $id): array { |
|
118 | + function(string $route, int $id): array { |
|
119 | 119 | $parameters = []; |
120 | 120 | $parameters['_first'] = $id; |
121 | 121 | $parameters['id'] = $id * 2; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $route = '/route/[i:id]'; |
148 | 148 | $router = $this->getRouter(); |
149 | 149 | |
150 | - $router->addRoute($route, function (int $id): int { |
|
150 | + $router->addRoute($route, function(int $id): int { |
|
151 | 151 | return $id; |
152 | 152 | }); |
153 | 153 | $router->registerMiddleware('*', /** |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * route |
157 | 157 | * @psalm-param int $id parameter |
158 | 158 | */ |
159 | - function (string $route, int $id): int { |
|
159 | + function(string $route, int $id): int { |
|
160 | 160 | return $id; |
161 | 161 | }); |
162 | 162 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(strict_types = 1); |
|
2 | +declare(strict_types=1); |
|
3 | 3 | namespace Mezon\Router\Tests\Base; |
4 | 4 | |
5 | 5 | use PHPUnit\Framework\TestCase; |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | { |
30 | 30 | // setup |
31 | 31 | $router = $this->getRouter(); |
32 | - $router->addRoute('/catalog/[i:foo]/', function () { |
|
32 | + $router->addRoute('/catalog/[i:foo]/', function() { |
|
33 | 33 | // do nothing |
34 | 34 | }); |
35 | 35 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | // setup |
50 | 50 | $_SERVER['REQUEST_METHOD'] = 'HEAD'; |
51 | 51 | $router = $this->getRouter(); |
52 | - $router->addRoute('/catalog/[i:foo]/', function () { |
|
52 | + $router->addRoute('/catalog/[i:foo]/', function() { |
|
53 | 53 | // do nothing |
54 | 54 | }); |
55 | 55 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | { |
68 | 68 | // setup |
69 | 69 | $router = $this->getRouter(); |
70 | - $router->addRoute('/catalog/[il:cat_id]/', function () { |
|
70 | + $router->addRoute('/catalog/[il:cat_id]/', function() { |
|
71 | 71 | return 1; |
72 | 72 | }); |
73 | 73 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | $exception = ''; |
91 | 91 | $router = $this->getRouter(); |
92 | - $router->addRoute('/catalog/[i:cat_id]', function () { |
|
92 | + $router->addRoute('/catalog/[i:cat_id]', function() { |
|
93 | 93 | return 1; |
94 | 94 | }); |
95 | 95 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | $exception = ''; |
118 | 118 | $router = $this->getRouter(); |
119 | - $router->addRoute('/catalog/[i:cat_id]', function () { |
|
119 | + $router->addRoute('/catalog/[i:cat_id]', function() { |
|
120 | 120 | return 1; |
121 | 121 | }); |
122 | 122 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $exception = ''; |
145 | 145 | $router = $this->getRouter(); |
146 | - $router->addRoute('/catalog/[i:item_id]', function () { |
|
146 | + $router->addRoute('/catalog/[i:item_id]', function() { |
|
147 | 147 | return 1; |
148 | 148 | }); |
149 | 149 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | { |
189 | 189 | // setup |
190 | 190 | $router = $this->getRouter(); |
191 | - $router->addRoute($route, function () { |
|
191 | + $router->addRoute($route, function() { |
|
192 | 192 | // do nothing |
193 | 193 | }); |
194 | 194 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | { |
207 | 207 | // setup |
208 | 208 | $router = $this->getRouter(); |
209 | - $router->addRoute('/catalog/[unexisting-type:i]/item/', function () { |
|
209 | + $router->addRoute('/catalog/[unexisting-type:i]/item/', function() { |
|
210 | 210 | return 1; |
211 | 211 | }); |
212 | 212 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | { |
227 | 227 | // setup |
228 | 228 | $router = $this->getRouter(); |
229 | - $router->addRoute('/catalog/[i:cat_id]/item/[unexisting-type-trace:item_id]/', function () { |
|
229 | + $router->addRoute('/catalog/[i:cat_id]/item/[unexisting-type-trace:item_id]/', function() { |
|
230 | 230 | return 1; |
231 | 231 | }); |
232 | 232 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(strict_types = 1); |
|
2 | +declare(strict_types=1); |
|
3 | 3 | namespace Mezon\Router\Tests\Base; |
4 | 4 | |
5 | 5 | use PHPUnit\Framework\TestCase; |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | { |
32 | 32 | return [ |
33 | 33 | [ |
34 | - function (): bool { |
|
34 | + function(): bool { |
|
35 | 35 | return true; |
36 | 36 | }, |
37 | 37 | true |
38 | 38 | ], |
39 | 39 | [ |
40 | - function (): bool { |
|
40 | + function(): bool { |
|
41 | 41 | return false; |
42 | 42 | }, |
43 | 43 | false |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare(strict_types = 1); |
|
2 | +declare(strict_types=1); |
|
3 | 3 | namespace Mezon\Router\Tests\Base; |
4 | 4 | |
5 | 5 | use Mezon\Router\Tests\Utils; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | public function testArrayRoutes(): void |
83 | 83 | { |
84 | 84 | $router = $this->getRouter(); |
85 | - $router->addRoute('/part1/part2/', function (string $route): string { |
|
85 | + $router->addRoute('/part1/part2/', function(string $route): string { |
|
86 | 86 | return $route; |
87 | 87 | }, 'GET'); |
88 | 88 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | $this->setRequestUri('/catalog/item/'); |
104 | 104 | |
105 | 105 | $router = $this->getRouter(); |
106 | - $router->addRoute('/catalog/item/', function (string $route): string { |
|
106 | + $router->addRoute('/catalog/item/', function(string $route): string { |
|
107 | 107 | return $route; |
108 | 108 | }, 'GET'); |
109 | 109 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $this->setRequestUri('/'); |
124 | 124 | |
125 | 125 | $router = $this->getRouter(); |
126 | - $router->addRoute('/index/', function (string $route): string { |
|
126 | + $router->addRoute('/index/', function(string $route): string { |
|
127 | 127 | return $route; |
128 | 128 | }, 'GET'); |
129 | 129 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $this->setRequestUri('/'); |
145 | 145 | |
146 | 146 | $router = $this->getRouter(); |
147 | - $router->addRoute('/index/', function (string $route): string { |
|
147 | + $router->addRoute('/index/', function(string $route): string { |
|
148 | 148 | return $route; |
149 | 149 | }, [ |
150 | 150 | 'GET', |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | { |
269 | 269 | // setup |
270 | 270 | $router = $this->getRouter(); |
271 | - $router->addRoute('/route-to-clear/', function () use ($method) { |
|
271 | + $router->addRoute('/route-to-clear/', function() use ($method) { |
|
272 | 272 | return $method; |
273 | 273 | }, $method); |
274 | 274 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $_SERVER['REQUEST_METHOD'] = $method; |
292 | 292 | |
293 | 293 | $router = $this->getRouter(); |
294 | - $router->addRoute('/catalog/', function (string $route): string { |
|
294 | + $router->addRoute('/catalog/', function(string $route): string { |
|
295 | 295 | return $route; |
296 | 296 | }, $method); |
297 | 297 | |
@@ -308,10 +308,10 @@ discard block |
||
308 | 308 | { |
309 | 309 | // setup |
310 | 310 | $router = $this->getRouter(); |
311 | - $router->addRoute('/searching-static-route/', function (string $route) { |
|
311 | + $router->addRoute('/searching-static-route/', function(string $route) { |
|
312 | 312 | return $route; |
313 | 313 | }); |
314 | - $router->addRoute('/searching-param-route/[i:id]/', function (string $route) { |
|
314 | + $router->addRoute('/searching-param-route/[i:id]/', function(string $route) { |
|
315 | 315 | return $route; |
316 | 316 | }); |
317 | 317 | |
@@ -328,12 +328,12 @@ discard block |
||
328 | 328 | { |
329 | 329 | // assertions |
330 | 330 | $this->expectException(\Exception::class); |
331 | - $this->expectExceptionCode(- 1); |
|
331 | + $this->expectExceptionCode(-1); |
|
332 | 332 | $this->expectExceptionMessage('Unsupported request method: "INVALID"'); |
333 | 333 | |
334 | 334 | // setup |
335 | 335 | $router = $this->getRouter(); |
336 | - $router->addRoute('/searching-static-route/', function (string $route) { |
|
336 | + $router->addRoute('/searching-static-route/', function(string $route) { |
|
337 | 337 | return $route; |
338 | 338 | }); |
339 | 339 | $_SERVER['REQUEST_METHOD'] = 'INVALID'; |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -declare(strict_types = 1); |
|
2 | +declare(strict_types=1); |
|
3 | 3 | namespace Mezon\Router\Tests\Simple; |
4 | 4 | |
5 | 5 | use Mezon\Router\RouterInterface; |