Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

What is setList in Rector?

Hello,

I needed to update the route naming syntax in my Laravel project. I managed to do it using Rector: https://github.com/rectorphp/rector and the rector-laravel extension package with the specific rules for Laravel: https://github.com/driftingly/rector-laravel

At first I tried setting the rector.php file like this:

    <?php
    
    declare(strict_types=1);
    
    use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
    use Rector\Config\RectorConfig;
    use RectorLaravel\Rector\StaticCall\RouteActionCallableRector;
    use Rector\Set\ValueObject\LevelSetList;
    
    return static function (RectorConfig $rectorConfig): void {
        $rectorConfig->paths([
            __DIR__ . '/routes'
        ]);
    
        $rectorConfig->ruleWithConfiguration(RouteActionCallableRector::class, [
            RouteActionCallableRector::NAMESPACE => 'App\Http\Controllers',
        ]);
    };

But it threw the following error:

[ERROR] Cannot autowire service "RectorLaravel\Rector\StaticCall\RouteActionCallableRector": argument

"$routerRegisterNodeAnalyzer" of method "__construct()" references class "RectorLaravel\NodeFactory\RouterRegisterNodeAnalyzer" but no such service exists.

Then I noticed I do not have a setList like the examples, so I added the first setList I found randomly:

    return static function (RectorConfig $rectorConfig): void {
        $rectorConfig->paths([
            __DIR__ . '/routes'
        ]);
    
        $rectorConfig->ruleWithConfiguration(RouteActionCallableRector::class, [
            RouteActionCallableRector::NAMESPACE => 'App\Http\Controllers',
        ]);
    
        // added this
        $rectorConfig->sets([
            LaravelSetList::LARAVEL_CODE_QUALITY
        ]);
    };

And it worked. But what exactly is the purpose of this setList? I just picked the first one that was autocompleted by the IDE. But there are many others like LaravelSetList::LARAVEL_100, LaravelSetList::LARAVEL_80, and so on.

Why was it necessary for the RouteActionCallableRector to work?

thanks

0 likes
2 replies
LaryAI's avatar
Level 58

The setList in Rector is a pre-defined set of rules that can be applied to a project. It is a convenient way to apply a group of rules that are commonly used together. In the provided example, the LaravelSetList::LARAVEL_CODE_QUALITY set was used, which includes a set of rules to improve the code quality of a Laravel project. Other sets, such as LaravelSetList::LARAVEL_100 and LaravelSetList::LARAVEL_80, include rules to enforce specific coding standards or to upgrade a project to a specific version of Laravel.

In summary, the setList is a way to apply a group of rules to a project, and the specific set used depends on the desired outcome.

JimNayzium's avatar

Is Laravel now built in to Rector and I would not no longer need to install the laravel dependency etc? I am in Laravel 11.14 and I got an error when trying:

In PackageDiscoveryTrait.php line 383:                                                                                                                                                                                                                    
  Could not find a matching version of package rector/laravel. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (stable).  

Please or to participate in this conversation.