From d7ebbe8041b011aef5de4b2abdc4f995fad100c2 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Fri, 3 Jan 2025 11:57:35 +0000 Subject: [PATCH 1/9] Test --- .../Fixture/skip_known_namespace.php.inc | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_known_namespace.php.inc diff --git a/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_known_namespace.php.inc b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_known_namespace.php.inc new file mode 100644 index 00000000..c2e1ea23 --- /dev/null +++ b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_known_namespace.php.inc @@ -0,0 +1,11 @@ + 'Admin'], function () { + Route::get('/users', 'SomeController@index'); +}); + +?> From 38aff9de3774a490c8d1d99d00fc4b049caea2f2 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Thu, 2 Jan 2025 21:25:40 +0000 Subject: [PATCH 2/9] Improve type hint --- src/Rector/StaticCall/RouteActionCallableRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rector/StaticCall/RouteActionCallableRector.php b/src/Rector/StaticCall/RouteActionCallableRector.php index 017f053c..64ee5558 100644 --- a/src/Rector/StaticCall/RouteActionCallableRector.php +++ b/src/Rector/StaticCall/RouteActionCallableRector.php @@ -91,7 +91,7 @@ public function getNodeTypes(): array /** * @param MethodCall|StaticCall $node */ - public function refactor(Node $node): ?Node + public function refactor(Node $node): MethodCall|StaticCall|null { if (! $this->routerRegisterNodeAnalyzer->isRegisterMethodStaticCall($node)) { return null; From 0b1faf7eea47f8aae2a80545d063708a382a9513 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Fri, 3 Jan 2025 12:23:56 +0000 Subject: [PATCH 3/9] Handles avoid groups with namespace --- .../RouterRegisterNodeAnalyzer.php | 40 +++++++++++++++++++ .../StaticCall/RouteActionCallableRector.php | 31 ++++++++++++++ .../Fixture/skip_group_namespace.php.inc | 27 +++++++++++++ .../Fixture/skip_known_namespace.php.inc | 11 ----- 4 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_group_namespace.php.inc delete mode 100644 tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_known_namespace.php.inc diff --git a/src/NodeFactory/RouterRegisterNodeAnalyzer.php b/src/NodeFactory/RouterRegisterNodeAnalyzer.php index 84f51569..fd2300df 100644 --- a/src/NodeFactory/RouterRegisterNodeAnalyzer.php +++ b/src/NodeFactory/RouterRegisterNodeAnalyzer.php @@ -4,10 +4,14 @@ namespace RectorLaravel\NodeFactory; +use PhpParser\Node\Arg; use PhpParser\Node\Expr; +use PhpParser\Node\Expr\Array_; +use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Identifier; +use PhpParser\Node\Scalar\String_; use PHPStan\Type\ObjectType; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\NodeTypeResolver; @@ -74,4 +78,40 @@ public function isRegisterFallback(Identifier|Expr $name): bool { return $this->nodeNameResolver->isName($name, 'fallback'); } + + public function isGroup(Identifier|Expr $name): bool + { + return $this->nodeNameResolver->isName($name, 'group'); + } + + public function getGroupNamespace(MethodCall|StaticCall $call): string|null|false + { + if (! isset($call->args[0]) || ! $call->args[0] instanceof Arg) { + return null; + } + + $firstArg = $call->args[0]->value; + if (! $firstArg instanceof Array_) { + return null; + } + + foreach ($firstArg->items as $item) { + if (! $item instanceof ArrayItem) { + continue; + } + + if ($item->key instanceof String_ && $item->key->value === 'namespace') { + + if ($item->value instanceof String_) { + return $item->value->value; + } + + // if we can't find the namespace value we specify it exists but is + // unreadable with false + return false; + } + } + + return null; + } } diff --git a/src/Rector/StaticCall/RouteActionCallableRector.php b/src/Rector/StaticCall/RouteActionCallableRector.php index 64ee5558..8a3a3ac1 100644 --- a/src/Rector/StaticCall/RouteActionCallableRector.php +++ b/src/Rector/StaticCall/RouteActionCallableRector.php @@ -42,6 +42,11 @@ final class RouteActionCallableRector extends AbstractRector implements Configur */ final public const NAMESPACE = 'namespace'; + /** + * @var string + */ + final public const NAMESPACE_ATTRIBUTE = 'group_namespace'; + /** * @var string */ @@ -93,10 +98,36 @@ public function getNodeTypes(): array */ public function refactor(Node $node): MethodCall|StaticCall|null { + if ($this->routerRegisterNodeAnalyzer->isGroup($node->name)) { + if (! isset($node->args[1]) || ! $node->args[1] instanceof Arg) { + return null; + } + + $this->traverseNodesWithCallable($node->args[1]->value, function (Node $node): Node|int|null { + if (! $node instanceof MethodCall && ! $node instanceof StaticCall) { + return null; + } + + if ($this->routerRegisterNodeAnalyzer->isRegisterMethodStaticCall($node)) { + $node->setAttribute(self::NAMESPACE_ATTRIBUTE, true); + } + + return null; + }); + + return null; + } + if (! $this->routerRegisterNodeAnalyzer->isRegisterMethodStaticCall($node)) { return null; } + $hasGroupNamespace = (bool) $node->getAttribute(self::NAMESPACE_ATTRIBUTE, false); + + if ($hasGroupNamespace) { + return null; + } + $position = $this->getActionPosition($node->name); if (! isset($node->args[$position])) { diff --git a/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_group_namespace.php.inc b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_group_namespace.php.inc new file mode 100644 index 00000000..99e06bfa --- /dev/null +++ b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_group_namespace.php.inc @@ -0,0 +1,27 @@ + 'Admin'], function () { + Route::get('/users', 'SomeController@index'); +}); + +Route::get('/users', 'SomeController@index'); + +?> +----- + 'Admin'], function () { + Route::get('/users', 'SomeController@index'); +}); + +Route::get('/users', [\RectorLaravel\Tests\Rector\StaticCall\RouteActionCallableRector\Source\SomeController::class, 'index']); + +?> diff --git a/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_known_namespace.php.inc b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_known_namespace.php.inc deleted file mode 100644 index c2e1ea23..00000000 --- a/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_known_namespace.php.inc +++ /dev/null @@ -1,11 +0,0 @@ - 'Admin'], function () { - Route::get('/users', 'SomeController@index'); -}); - -?> From 6ef9d63361bfbf8ba0083087949c42553cd6033d Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Fri, 3 Jan 2025 12:42:10 +0000 Subject: [PATCH 4/9] Working with one level of groups --- .../StaticCall/RouteActionCallableRector.php | 18 ++++++++++++------ .../Fixture/fixture.php.inc | 8 ++++++++ ...nc => skip_invalid_group_namespace.php.inc} | 4 ++-- .../Source/SomeNamespace/SomeController.php | 8 ++++++++ 4 files changed, 30 insertions(+), 8 deletions(-) rename tests/Rector/StaticCall/RouteActionCallableRector/Fixture/{skip_group_namespace.php.inc => skip_invalid_group_namespace.php.inc} (80%) create mode 100644 tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeNamespace/SomeController.php diff --git a/src/Rector/StaticCall/RouteActionCallableRector.php b/src/Rector/StaticCall/RouteActionCallableRector.php index 8a3a3ac1..8ee99098 100644 --- a/src/Rector/StaticCall/RouteActionCallableRector.php +++ b/src/Rector/StaticCall/RouteActionCallableRector.php @@ -103,13 +103,15 @@ public function refactor(Node $node): MethodCall|StaticCall|null return null; } - $this->traverseNodesWithCallable($node->args[1]->value, function (Node $node): Node|int|null { + $namespace = $this->routerRegisterNodeAnalyzer->getGroupNamespace($node); + + $this->traverseNodesWithCallable($node->args[1]->value, function (Node $node) use ($namespace): Node|int|null { if (! $node instanceof MethodCall && ! $node instanceof StaticCall) { return null; } if ($this->routerRegisterNodeAnalyzer->isRegisterMethodStaticCall($node)) { - $node->setAttribute(self::NAMESPACE_ATTRIBUTE, true); + $node->setAttribute(self::NAMESPACE_ATTRIBUTE, $namespace); } return null; @@ -122,9 +124,10 @@ public function refactor(Node $node): MethodCall|StaticCall|null return null; } - $hasGroupNamespace = (bool) $node->getAttribute(self::NAMESPACE_ATTRIBUTE, false); + $groupNamespace = $node->getAttribute(self::NAMESPACE_ATTRIBUTE); - if ($hasGroupNamespace) { + // if the route is in a namespace but can't be resolve to a value, don't continue + if (! is_string($groupNamespace) && ! is_null($groupNamespace)) { return null; } @@ -141,7 +144,7 @@ public function refactor(Node $node): MethodCall|StaticCall|null $arg = $node->args[$position]; $argValue = $this->valueResolver->getValue($arg->value); - $segments = $this->resolveControllerFromAction($argValue); + $segments = $this->resolveControllerFromAction($argValue, $groupNamespace); if ($segments === null) { return null; } @@ -213,7 +216,7 @@ public function configure(array $configuration): void /** * @return array{string, string}|null */ - private function resolveControllerFromAction(mixed $action): ?array + private function resolveControllerFromAction(mixed $action, ?string $groupNamespace = null): ?array { if (! $this->isActionString($action)) { return null; @@ -230,6 +233,9 @@ private function resolveControllerFromAction(mixed $action): ?array [$controller, $method] = $segments; $namespace = $this->getNamespace($this->file->getFilePath()); + if ($groupNamespace !== null) { + $namespace .= '\\' . $groupNamespace; + } if (! str_starts_with($controller, '\\')) { $controller = $namespace . '\\' . $controller; } diff --git a/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/fixture.php.inc b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/fixture.php.inc index ebb8f606..0d81a37a 100644 --- a/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/fixture.php.inc +++ b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/fixture.php.inc @@ -16,6 +16,10 @@ Route::fallback('SomeController@index'); Route::options('/users', 'SomeController@index'); Route::middleware([])->options('/users', 'SomeController@index'); +Route::group(['namespace' => 'SomeNamespace'], function () { + Route::get('/users', 'SomeController@index'); +}) + ?> ----- options('/users', [\RectorLaravel\Tests\Rector\StaticCall\RouteActionCallableRector\Source\SomeController::class, 'index']); +Route::group(['namespace' => 'SomeNamespace'], function () { + Route::get('/users', [\RectorLaravel\Tests\Rector\StaticCall\RouteActionCallableRector\Source\SomeNamespace\SomeController::class, 'index']); +}) + ?> diff --git a/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_group_namespace.php.inc b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_invalid_group_namespace.php.inc similarity index 80% rename from tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_group_namespace.php.inc rename to tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_invalid_group_namespace.php.inc index 99e06bfa..60f3088d 100644 --- a/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_group_namespace.php.inc +++ b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_invalid_group_namespace.php.inc @@ -4,7 +4,7 @@ namespace RectorLaravel\Tests\Rector\StaticCall\RouteActionCallableRector\Fixtur use Illuminate\Support\Facades\Route; -Route::group(['namespace' => 'Admin'], function () { +Route::group(['namespace' => 'Some' . 'Namespace'], function () { Route::get('/users', 'SomeController@index'); }); @@ -18,7 +18,7 @@ namespace RectorLaravel\Tests\Rector\StaticCall\RouteActionCallableRector\Fixtur use Illuminate\Support\Facades\Route; -Route::group(['namespace' => 'Admin'], function () { +Route::group(['namespace' => 'Some' . 'Namespace'], function () { Route::get('/users', 'SomeController@index'); }); diff --git a/tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeNamespace/SomeController.php b/tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeNamespace/SomeController.php new file mode 100644 index 00000000..3b120608 --- /dev/null +++ b/tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeNamespace/SomeController.php @@ -0,0 +1,8 @@ + Date: Fri, 3 Jan 2025 12:56:07 +0000 Subject: [PATCH 5/9] Handles nested groups --- docs/rector_rules_overview.md | 5 +++ .../StaticCall/RouteActionCallableRector.php | 27 ++++++++++++++-- .../Fixture/nested_groups.php.inc | 31 +++++++++++++++++++ .../skip_invalid_group_namespace.php.inc | 18 +++++++++++ .../SomeOtherNamespace/SomeController.php | 8 +++++ 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 tests/Rector/StaticCall/RouteActionCallableRector/Fixture/nested_groups.php.inc create mode 100644 tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeNamespace/SomeOtherNamespace/SomeController.php diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md index f0f192d7..11ed7dbf 100644 --- a/docs/rector_rules_overview.md +++ b/docs/rector_rules_overview.md @@ -1296,6 +1296,11 @@ Use PHP callable syntax instead of string syntax for controller route declaratio ```diff -Route::get('/users', 'UserController@index'); +Route::get('/users', [\App\Http\Controllers\UserController::class, 'index']); + + Route::group(['namespace' => 'Admin'], function () { +- Route::get('/users', 'UserController@index'); ++ Route::get('/users', [\App\Http\Controllers\Admin\UserController::class, 'index']); + }) ```
diff --git a/src/Rector/StaticCall/RouteActionCallableRector.php b/src/Rector/StaticCall/RouteActionCallableRector.php index 8ee99098..403e31c8 100644 --- a/src/Rector/StaticCall/RouteActionCallableRector.php +++ b/src/Rector/StaticCall/RouteActionCallableRector.php @@ -4,6 +4,7 @@ namespace RectorLaravel\Rector\StaticCall; +use Illuminate\Support\Facades\Route; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\ArrayItem; @@ -71,11 +72,19 @@ public function getRuleDefinition(): RuleDefinition new ConfiguredCodeSample( <<<'CODE_SAMPLE' Route::get('/users', 'UserController@index'); + +Route::group(['namespace' => 'Admin'], function () { + Route::get('/users', 'UserController@index'); +}) CODE_SAMPLE , <<<'CODE_SAMPLE' Route::get('/users', [\App\Http\Controllers\UserController::class, 'index']); + +Route::group(['namespace' => 'Admin'], function () { + Route::get('/users', [\App\Http\Controllers\Admin\UserController::class, 'index']); +}) CODE_SAMPLE , [ @@ -105,12 +114,26 @@ public function refactor(Node $node): MethodCall|StaticCall|null $namespace = $this->routerRegisterNodeAnalyzer->getGroupNamespace($node); + $groupNamespace = $node->getAttribute(self::NAMESPACE_ATTRIBUTE); + + // if the route is in a namespace but can't be resolved to a value, don't continue + if (! is_string($groupNamespace) && ! is_null($groupNamespace)) { + return null; + } + + if (is_string($groupNamespace)) { + $namespace = $groupNamespace . '\\' . $namespace; + } + $this->traverseNodesWithCallable($node->args[1]->value, function (Node $node) use ($namespace): Node|int|null { if (! $node instanceof MethodCall && ! $node instanceof StaticCall) { return null; } - if ($this->routerRegisterNodeAnalyzer->isRegisterMethodStaticCall($node)) { + if ( + $this->routerRegisterNodeAnalyzer->isRegisterMethodStaticCall($node) || + $this->routerRegisterNodeAnalyzer->isGroup($node->name) + ) { $node->setAttribute(self::NAMESPACE_ATTRIBUTE, $namespace); } @@ -126,7 +149,7 @@ public function refactor(Node $node): MethodCall|StaticCall|null $groupNamespace = $node->getAttribute(self::NAMESPACE_ATTRIBUTE); - // if the route is in a namespace but can't be resolve to a value, don't continue + // if the route is in a namespace but can't be resolved to a value, don't continue if (! is_string($groupNamespace) && ! is_null($groupNamespace)) { return null; } diff --git a/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/nested_groups.php.inc b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/nested_groups.php.inc new file mode 100644 index 00000000..23d2eff0 --- /dev/null +++ b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/nested_groups.php.inc @@ -0,0 +1,31 @@ + 'SomeNamespace'], function () { + Route::group(['namespace' => 'SomeOtherNamespace'], function () { + Route::get('/users', 'SomeController@index'); + }); + + Route::get('/users', 'SomeController@index'); +}); + +?> +----- + 'SomeNamespace'], function () { + Route::group(['namespace' => 'SomeOtherNamespace'], function () { + Route::get('/users', [\RectorLaravel\Tests\Rector\StaticCall\RouteActionCallableRector\Source\SomeNamespace\SomeOtherNamespace\SomeController::class, 'index']); + }); + + Route::get('/users', [\RectorLaravel\Tests\Rector\StaticCall\RouteActionCallableRector\Source\SomeNamespace\SomeController::class, 'index']); +}); + +?> diff --git a/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_invalid_group_namespace.php.inc b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_invalid_group_namespace.php.inc index 60f3088d..0afea3dd 100644 --- a/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_invalid_group_namespace.php.inc +++ b/tests/Rector/StaticCall/RouteActionCallableRector/Fixture/skip_invalid_group_namespace.php.inc @@ -4,10 +4,19 @@ namespace RectorLaravel\Tests\Rector\StaticCall\RouteActionCallableRector\Fixtur use Illuminate\Support\Facades\Route; +// the concat should make the rule ignore the group and any routes within it Route::group(['namespace' => 'Some' . 'Namespace'], function () { Route::get('/users', 'SomeController@index'); }); +Route::group(['namespace' => 'SomeNamespace'], function () { + Route::get('/users', 'SomeController@index'); + + Route::group(['namespace' => 'SomeOther' . 'Namespace'], function () { + Route::get('/users', 'SomeController@index'); + }); +}); + Route::get('/users', 'SomeController@index'); ?> @@ -18,10 +27,19 @@ namespace RectorLaravel\Tests\Rector\StaticCall\RouteActionCallableRector\Fixtur use Illuminate\Support\Facades\Route; +// the concat should make the rule ignore the group and any routes within it Route::group(['namespace' => 'Some' . 'Namespace'], function () { Route::get('/users', 'SomeController@index'); }); +Route::group(['namespace' => 'SomeNamespace'], function () { + Route::get('/users', [\RectorLaravel\Tests\Rector\StaticCall\RouteActionCallableRector\Source\SomeNamespace\SomeController::class, 'index']); + + Route::group(['namespace' => 'SomeOther' . 'Namespace'], function () { + Route::get('/users', 'SomeController@index'); + }); +}); + Route::get('/users', [\RectorLaravel\Tests\Rector\StaticCall\RouteActionCallableRector\Source\SomeController::class, 'index']); ?> diff --git a/tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeNamespace/SomeOtherNamespace/SomeController.php b/tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeNamespace/SomeOtherNamespace/SomeController.php new file mode 100644 index 00000000..14e06420 --- /dev/null +++ b/tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeNamespace/SomeOtherNamespace/SomeController.php @@ -0,0 +1,8 @@ + Date: Fri, 3 Jan 2025 13:05:48 +0000 Subject: [PATCH 6/9] const change --- src/Rector/StaticCall/RouteActionCallableRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rector/StaticCall/RouteActionCallableRector.php b/src/Rector/StaticCall/RouteActionCallableRector.php index 403e31c8..bd6e0667 100644 --- a/src/Rector/StaticCall/RouteActionCallableRector.php +++ b/src/Rector/StaticCall/RouteActionCallableRector.php @@ -46,7 +46,7 @@ final class RouteActionCallableRector extends AbstractRector implements Configur /** * @var string */ - final public const NAMESPACE_ATTRIBUTE = 'group_namespace'; + final public const NAMESPACE_ATTRIBUTE = 'laravel_route_group_namespace'; /** * @var string From f9c86cf6357145784f84ee765f9810925824cc1d Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Mon, 6 Jan 2025 21:09:23 +0000 Subject: [PATCH 7/9] Adds the route rule to the L8 set --- config/sets/laravel80.php | 5 +++ stubs/App/Http/Controllers/FooController.php | 8 +++++ .../Laravel80/Fixture/handle_routing.php.inc | 19 ++++++++++++ tests/Sets/Laravel80/Laravel80Test.php | 31 +++++++++++++++++++ .../Sets/Laravel80/config/configured_rule.php | 9 ++++++ 5 files changed, 72 insertions(+) create mode 100644 stubs/App/Http/Controllers/FooController.php create mode 100644 tests/Sets/Laravel80/Fixture/handle_routing.php.inc create mode 100644 tests/Sets/Laravel80/Laravel80Test.php create mode 100644 tests/Sets/Laravel80/config/configured_rule.php diff --git a/config/sets/laravel80.php b/config/sets/laravel80.php index 7508d113..a7466d65 100644 --- a/config/sets/laravel80.php +++ b/config/sets/laravel80.php @@ -13,6 +13,7 @@ use Rector\Renaming\ValueObject\RenameProperty; use RectorLaravel\Rector\ClassMethod\AddArgumentDefaultValueRector; use RectorLaravel\Rector\ClassMethod\AddParentRegisterToEventServiceProviderRector; +use RectorLaravel\Rector\StaticCall\RouteActionCallableRector; use RectorLaravel\ValueObject\AddArgumentDefaultValue; // see https://laravel.com/docs/8.x/upgrade @@ -59,4 +60,8 @@ // https://github.com/laravel/framework/commit/f9374fa5fb0450721fb2f90e96adef9d409b112c new MethodCallRename('Illuminate\Testing\TestResponse', 'decodeResponseJson', 'json'), ]); + + // https://laravel.com/docs/8.x/upgrade#automatic-controller-namespace-prefixing + $rectorConfig + ->ruleWithConfiguration(RouteActionCallableRector::class, []); }; diff --git a/stubs/App/Http/Controllers/FooController.php b/stubs/App/Http/Controllers/FooController.php new file mode 100644 index 00000000..1e274426 --- /dev/null +++ b/stubs/App/Http/Controllers/FooController.php @@ -0,0 +1,8 @@ + +----- + diff --git a/tests/Sets/Laravel80/Laravel80Test.php b/tests/Sets/Laravel80/Laravel80Test.php new file mode 100644 index 00000000..8dd2e490 --- /dev/null +++ b/tests/Sets/Laravel80/Laravel80Test.php @@ -0,0 +1,31 @@ +doTestFile($filePath); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Sets/Laravel80/config/configured_rule.php b/tests/Sets/Laravel80/config/configured_rule.php new file mode 100644 index 00000000..53ab4574 --- /dev/null +++ b/tests/Sets/Laravel80/config/configured_rule.php @@ -0,0 +1,9 @@ +import(__DIR__ . '/../../../../config/sets/Laravel80.php'); +}; From 2db41944ca286a2084a7d8da05f7ecb03ca41f73 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Tue, 7 Jan 2025 09:08:02 +0000 Subject: [PATCH 8/9] Fix config reference --- tests/Sets/Laravel80/config/configured_rule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Sets/Laravel80/config/configured_rule.php b/tests/Sets/Laravel80/config/configured_rule.php index 53ab4574..c563bd5b 100644 --- a/tests/Sets/Laravel80/config/configured_rule.php +++ b/tests/Sets/Laravel80/config/configured_rule.php @@ -5,5 +5,5 @@ use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { - $rectorConfig->import(__DIR__ . '/../../../../config/sets/Laravel80.php'); + $rectorConfig->import(__DIR__ . '/../../../../config/sets/laravel80.php'); }; From fc851db4a6532f93a728dbc00f4e37d3efdfe099 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Tue, 7 Jan 2025 20:22:54 +0000 Subject: [PATCH 9/9] Revert "Adds the route rule to the L8 set" This reverts commit f9c86cf6357145784f84ee765f9810925824cc1d. # Conflicts: # tests/Sets/Laravel80/config/configured_rule.php --- config/sets/laravel80.php | 5 --- stubs/App/Http/Controllers/FooController.php | 8 ----- .../Laravel80/Fixture/handle_routing.php.inc | 19 ------------ tests/Sets/Laravel80/Laravel80Test.php | 31 ------------------- .../Sets/Laravel80/config/configured_rule.php | 9 ------ 5 files changed, 72 deletions(-) delete mode 100644 stubs/App/Http/Controllers/FooController.php delete mode 100644 tests/Sets/Laravel80/Fixture/handle_routing.php.inc delete mode 100644 tests/Sets/Laravel80/Laravel80Test.php delete mode 100644 tests/Sets/Laravel80/config/configured_rule.php diff --git a/config/sets/laravel80.php b/config/sets/laravel80.php index a7466d65..7508d113 100644 --- a/config/sets/laravel80.php +++ b/config/sets/laravel80.php @@ -13,7 +13,6 @@ use Rector\Renaming\ValueObject\RenameProperty; use RectorLaravel\Rector\ClassMethod\AddArgumentDefaultValueRector; use RectorLaravel\Rector\ClassMethod\AddParentRegisterToEventServiceProviderRector; -use RectorLaravel\Rector\StaticCall\RouteActionCallableRector; use RectorLaravel\ValueObject\AddArgumentDefaultValue; // see https://laravel.com/docs/8.x/upgrade @@ -60,8 +59,4 @@ // https://github.com/laravel/framework/commit/f9374fa5fb0450721fb2f90e96adef9d409b112c new MethodCallRename('Illuminate\Testing\TestResponse', 'decodeResponseJson', 'json'), ]); - - // https://laravel.com/docs/8.x/upgrade#automatic-controller-namespace-prefixing - $rectorConfig - ->ruleWithConfiguration(RouteActionCallableRector::class, []); }; diff --git a/stubs/App/Http/Controllers/FooController.php b/stubs/App/Http/Controllers/FooController.php deleted file mode 100644 index 1e274426..00000000 --- a/stubs/App/Http/Controllers/FooController.php +++ /dev/null @@ -1,8 +0,0 @@ - ------ - diff --git a/tests/Sets/Laravel80/Laravel80Test.php b/tests/Sets/Laravel80/Laravel80Test.php deleted file mode 100644 index 8dd2e490..00000000 --- a/tests/Sets/Laravel80/Laravel80Test.php +++ /dev/null @@ -1,31 +0,0 @@ -doTestFile($filePath); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/tests/Sets/Laravel80/config/configured_rule.php b/tests/Sets/Laravel80/config/configured_rule.php deleted file mode 100644 index c563bd5b..00000000 --- a/tests/Sets/Laravel80/config/configured_rule.php +++ /dev/null @@ -1,9 +0,0 @@ -import(__DIR__ . '/../../../../config/sets/laravel80.php'); -};