Set Lists

Prepared Sets

You can use particular single rules, or whole list of rules, called "set lists":

<?php

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPreparedSets(
        deadCode: true,
        codeQuality: true,
        codingStyle: true,
        naming: true,
        privatization: true,
        typeDeclarations: true,
        rectorPreset: true,
        // ...
    );

That way you can include a group of rules that focus on a certain topic. It makes the config small and clear. Try autocomplete in your IDE to see all available prepared sets.

A prepared set enables every rule in it at once. On an existing project, start with levels instead and switch to the set once the level covers it.

PHP Sets

The best practise is to use PHP version defined in composer.json. Rector will automatically pick it up with empty ->withPhpSets() method:

<?php

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPhpSets();

Are you on a legacy project and want to upgrade gradually? Prefer ->withPhpLevel() over the full set and raise it one step at a time. See Levels.

If you're on PHP 8+, you can use ->withPhpSets() with named arguments:

-   ->withSets([SetList::PHP_74]);
+   ->withPhpSets(php80: true);

That way you can use all the sets that are needed to upgrade your code to the desired PHP version in single line.

Community or External Sets

How can I use Rector with community sets or my custom one?

<?php

use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;

return RectorConfig::configure()
    ->withSets([
        DoctrineSetList::DOCTRINE_CODE_QUALITY,
        __DIR__.'/config/rector-custom-set.php'
    ]);