Skip to content

Commit 7aaea46

Browse files
committed
Revert Rector changes
1 parent 5087a11 commit 7aaea46

23 files changed

Lines changed: 260 additions & 203 deletions

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"php-coveralls/php-coveralls": "^2.4",
3232
"php-di/php-di": "^7.1.1",
3333
"phpunit/phpunit": "^12",
34-
"rector/rector": "^2.1",
3534
"squizlabs/php_codesniffer": "^3.6.0"
3635
},
3736
"autoload": {

rector.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Helpers/Formatting.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Formatting
66
{
77
public static function removeTrailingSlash($input)
88
{
9-
return rtrim((string) $input, '/\\');
9+
return rtrim($input, '/\\');
1010
}
1111

1212
public static function addTrailingSlash($input)
@@ -16,7 +16,7 @@ public static function addTrailingSlash($input)
1616

1717
public static function removeLeadingSlash($input)
1818
{
19-
return ltrim((string) $input, '/\\');
19+
return ltrim($input, '/\\');
2020
}
2121

2222
public static function addLeadingSlash($input)

src/Route.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,34 @@ class Route
2121
use Macroable;
2222

2323
private $uri;
24+
private $methods = [];
2425
private $routeAction;
2526
private $name;
27+
private $invoker = null;
28+
private $middlewareResolver = null;
2629
private $middleware = [];
2730
private $paramConstraints = [];
2831
private $controllerName = null;
2932
private $controllerMethod = null;
3033

3134
public function __construct(
32-
private array $methods,
35+
array $methods,
3336
string $uri,
3437
$action,
35-
private ?\Rareloop\Router\Invoker $invoker = null,
36-
private ?\Rareloop\Router\MiddlewareResolver $middlewareResolver = null
38+
?Invoker $invoker = null,
39+
?MiddlewareResolver $resolver = null
3740
) {
41+
$this->invoker = $invoker;
42+
$this->middlewareResolver = $resolver;
43+
44+
$this->methods = $methods;
3845
$this->setUri($uri);
3946
$this->setAction($action);
4047
}
4148

4249
private function setUri($uri)
4350
{
44-
$this->uri = rtrim((string) $uri, ' /');
51+
$this->uri = rtrim($uri, ' /');
4552
}
4653

4754
private function setAction($action)

src/RouteAction.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,15 @@ public function getMiddleware(): array
151151

152152
$allControllerMiddleware = array_filter(
153153
$this->getController()->getControllerMiddleware(),
154-
fn(ControllerMiddleware $middleware) => !$middleware->excludedForMethod($this->controllerMethod)
154+
function (ControllerMiddleware $middleware) {
155+
return !$middleware->excludedForMethod($this->controllerMethod);
156+
}
155157
);
156158

157159
return array_map(
158-
fn($controllerMiddleware) => $controllerMiddleware->middleware(),
160+
function ($controllerMiddleware) {
161+
return $controllerMiddleware->middleware();
162+
},
159163
$allControllerMiddleware
160164
);
161165
}
@@ -171,7 +175,7 @@ private function convertClassStringToFactory($string): Closure
171175
$this->controllerName = null;
172176
$this->controllerMethod = null;
173177

174-
@[$className, $method] = explode('@', $string);
178+
@list($className, $method) = explode('@', $string);
175179

176180
if (!isset($className) || !isset($method)) {
177181
throw new RouteClassStringParseException('Could not parse route controller from string: `' . $string . '`');
@@ -200,7 +204,9 @@ private function convertClassStringToFactory($string): Closure
200204
return [$controller, $method];
201205
}
202206

203-
return fn($params = null) => $controller->$method($params);
207+
return function ($params = null) use ($controller, $method) {
208+
return $controller->$method($params);
209+
};
204210
};
205211
}
206212

@@ -218,7 +224,7 @@ public function getActionName()
218224
}
219225

220226
if (is_callable($this->callable, false, $callableName)) {
221-
[$controller, $method] = explode('::', $callableName);
227+
list($controller, $method) = explode('::', $callableName);
222228

223229
if ($controller === 'Closure') {
224230
return $controller;

src/RouteGroup.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
class RouteGroup implements Routable
1010
{
1111
use VerbShortcutsTrait, Macroable;
12+
13+
protected $router;
1214
protected $prefix;
1315
protected $middleware = [];
1416

15-
public function __construct($params, protected $router)
17+
public function __construct($params, $router)
1618
{
1719
$prefix = null;
1820
$middleware = [];
@@ -33,6 +35,7 @@ public function __construct($params, protected $router)
3335
}
3436

3537
$this->prefix = is_string($prefix) ? trim($prefix, ' /') : null;
38+
$this->router = $router;
3639
}
3740

3841
private function appendPrefixToUri(string $uri)

src/RouteParams.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
class RouteParams implements \Iterator
66
{
77
private $position = 0;
8+
private $params = [];
89

9-
public function __construct(private array $params)
10+
public function __construct(array $params)
1011
{
12+
$this->params = $params;
1113
}
1214

1315
public function __get($key)

src/Router.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ private function convertRouteToAltoRouterUri(Route $route, AltoRouter $altoRoute
7979
{
8080
$output = $route->getUri();
8181

82-
preg_match_all('/{\s*([a-zA-Z0-9]+\??)\s*}/s', (string) $route->getUri(), $matches);
82+
preg_match_all('/{\s*([a-zA-Z0-9]+\??)\s*}/s', $route->getUri(), $matches);
8383

8484
$paramConstraints = $route->getParamConstraints();
8585

8686
for ($i = 0; $i < count($matches[0]); $i++) {
8787
$match = $matches[0][$i];
8888
$paramKey = $matches[1][$i];
8989

90-
$optional = str_ends_with($paramKey, '?');
90+
$optional = substr($paramKey, -1) === '?';
9191
$paramKey = trim($paramKey, '?');
9292

9393
$regex = $paramConstraints[$paramKey] ?? null;
@@ -109,7 +109,7 @@ private function convertRouteToAltoRouterUri(Route $route, AltoRouter $altoRoute
109109
$output = str_replace($match, $replacement, $output);
110110
}
111111

112-
return ltrim((string) $output, ' /');
112+
return ltrim($output, ' /');
113113
}
114114

115115
public function map(array $verbs, string $uri, $callback): Route
@@ -180,7 +180,9 @@ protected function handle($route, $request, $params)
180180

181181
// Apply all the base middleware and trigger the route handler as the last in the chain
182182
$middlewares = array_merge($this->baseMiddleware, [
183-
fn($request) => $route->handle($request, $params),
183+
function ($request) use ($route, $params) {
184+
return $route->handle($request, $params);
185+
},
184186
]);
185187

186188
// Create and process the dispatcher
@@ -197,7 +199,9 @@ protected function handle($route, $request, $params)
197199

198200
public function has(string $name)
199201
{
200-
$routes = array_filter($this->routes, fn($route) => $route->getName() === $name);
202+
$routes = array_filter($this->routes, function ($route) use ($name) {
203+
return $route->getName() === $name;
204+
});
201205

202206
return count($routes) > 0;
203207
}
@@ -223,7 +227,7 @@ public function url(string $name, $params = [])
223227
$regex = $paramConstraints[$key] ?? false;
224228

225229
if ($regex) {
226-
if (!preg_match('/' . $regex . '/', (string) $value)) {
230+
if (!preg_match('/' . $regex . '/', $value)) {
227231
throw new RouteParamFailedConstraintException(
228232
'Value `' . $value . '` for param `' . $key . '` fails constraint `' . $regex . '`'
229233
);
@@ -234,7 +238,7 @@ public function url(string $name, $params = [])
234238

235239
try {
236240
return $this->altoRouter->generate($name, $params);
237-
} catch (\Exception) {
241+
} catch (\Exception $e) {
238242
throw new NamedRouteNotFoundException($name);
239243
}
240244
}

tests/ControllerMiddlewareOptionsTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace Rareloop\Router\Test;
44

5-
use PHPUnit\Framework\Attributes\Test;
65
use PHPUnit\Framework\TestCase;
76
use Rareloop\Router\ControllerMiddlewareOptions;
87

98
class ControllerMiddlewareOptionsTest extends TestCase
109
{
11-
#[Test]
10+
/** @test */
1211
public function by_default_no_methods_are_excluded()
1312
{
1413
$options = new ControllerMiddlewareOptions;
@@ -17,15 +16,15 @@ public function by_default_no_methods_are_excluded()
1716
$this->assertFalse($options->excludedForMethod('bar'));
1817
}
1918

20-
#[Test]
19+
/** @test */
2120
public function only_is_chainable()
2221
{
2322
$options = new ControllerMiddlewareOptions;
2423

2524
$this->assertSame($options, $options->only('foo'));
2625
}
2726

28-
#[Test]
27+
/** @test */
2928
public function can_use_only_to_limit_methods()
3029
{
3130
$options = new ControllerMiddlewareOptions;
@@ -36,7 +35,7 @@ public function can_use_only_to_limit_methods()
3635
$this->assertTrue($options->excludedForMethod('bar'));
3736
}
3837

39-
#[Test]
38+
/** @test */
4039
public function can_use_only_to_limit_multiple_methods()
4140
{
4241
$options = new ControllerMiddlewareOptions;
@@ -48,15 +47,15 @@ public function can_use_only_to_limit_multiple_methods()
4847
$this->assertTrue($options->excludedForMethod('baz'));
4948
}
5049

51-
#[Test]
50+
/** @test */
5251
public function except_is_chainable()
5352
{
5453
$options = new ControllerMiddlewareOptions;
5554

5655
$this->assertSame($options, $options->except('foo'));
5756
}
5857

59-
#[Test]
58+
/** @test */
6059
public function can_use_except_to_limit_methods()
6160
{
6261
$options = new ControllerMiddlewareOptions;
@@ -67,7 +66,7 @@ public function can_use_except_to_limit_methods()
6766
$this->assertFalse($options->excludedForMethod('bar'));
6867
}
6968

70-
#[Test]
69+
/** @test */
7170
public function can_use_except_to_limit_multiple_methods()
7271
{
7372
$options = new ControllerMiddlewareOptions;

tests/ControllerMiddlewareTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
use Rareloop\Router\ControllerMiddleware;
77
use Rareloop\Router\ControllerMiddlewareOptions;
88
use Rareloop\Router\Test\Middleware\AddHeaderMiddleware;
9-
use PHPUnit\Framework\Attributes\Test;
109

1110
class ControllerMiddlewareTest extends TestCase
1211
{
13-
#[Test]
12+
/** @test */
1413
public function can_retrieve_middleware()
1514
{
1615
$middleware = new AddHeaderMiddleware('X-Header', 'testing123');
@@ -21,7 +20,7 @@ public function can_retrieve_middleware()
2120
$this->assertSame($middleware, $controllerMiddleware->middleware());
2221
}
2322

24-
#[Test]
23+
/** @test */
2524
public function can_retrieve_options()
2625
{
2726
$middleware = new AddHeaderMiddleware('X-Header', 'testing123');

0 commit comments

Comments
 (0)