ergebnis / rector-config
Provides a configuration factory and rule sets for rector/rector.
Requires
- php: ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0 || ~8.7.0
- ergebnis/rector-rules: ~1.22.0
- rector/rector: ~2.9.2
Requires (Dev)
- ergebnis/composer-normalize: ^2.57.0
- ergebnis/data-provider: ^3.7.1
- ergebnis/license: ^2.9.0
- ergebnis/php-cs-fixer-config: ^6.65.0
- ergebnis/phpstan-rules: ^2.17.1
- ergebnis/phpunit-slow-test-detector: ^2.27.0
- fakerphp/faker: ^1.24.1
- infection/infection: ~0.26.6
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.3.1
- phpstan/phpstan-deprecation-rules: ^2.0.6
- phpstan/phpstan-phpunit: ^2.1.2
- phpstan/phpstan-strict-rules: ^2.1.2
- phpunit/phpunit: ^9.6.38
- symfony/filesystem: ^5.4.54
- symfony/process: ^5.4.54
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-25 17:47:36 UTC
README
This project provides a composer package with a configuration factory and rule sets for rector/rector.
Installation
Run
composer require --dev ergebnis/rector-config
Usage
Configuration
Pick one of the rule sets:
Ergebnis\Rector\Config\RuleSet\Php53Ergebnis\Rector\Config\RuleSet\Php54Ergebnis\Rector\Config\RuleSet\Php55Ergebnis\Rector\Config\RuleSet\Php56Ergebnis\Rector\Config\RuleSet\Php70Ergebnis\Rector\Config\RuleSet\Php71Ergebnis\Rector\Config\RuleSet\Php72Ergebnis\Rector\Config\RuleSet\Php73Ergebnis\Rector\Config\RuleSet\Php74Ergebnis\Rector\Config\RuleSet\Php80Ergebnis\Rector\Config\RuleSet\Php81Ergebnis\Rector\Config\RuleSet\Php82Ergebnis\Rector\Config\RuleSet\Php83Ergebnis\Rector\Config\RuleSet\Php84Ergebnis\Rector\Config\RuleSet\Php85Ergebnis\Rector\Config\RuleSet\Php86
Each rule set lists every rule that rector/rector and ergebnis/rector-rules provide, except rules for frameworks and libraries, downgrade rules, and generic rules that only make sense with a project-specific configuration. A rule set enables or disables each of these rules explicitly and does not include any of the sets that rector/rector provides.
Create a configuration file rector.php in the root of your project:
<?php declare(strict_types=1); use Ergebnis\Rector\Config; $ruleSet = Config\RuleSet\Php53::create(); return Config\Factory::fromRuleSet($ruleSet) ->withCache(__DIR__ . '/.build/rector/') ->withPaths([ __DIR__ . '/src/', __DIR__ . '/test/', ]);
Config\Factory::fromRuleSet() returns the Rector\Configuration\RectorConfigBuilder of rector/rector, so you can continue to configure paths, skips, and sets for frameworks and libraries, for example the sets for PHPUnit:
<?php declare(strict_types=1); use Ergebnis\Rector\Config; +use Rector\PHPUnit; $ruleSet = Config\RuleSet\Php53::create(); return Config\Factory::fromRuleSet($ruleSet) ->withCache(__DIR__ . '/.build/rector/') ->withPaths([ __DIR__ . '/src/', __DIR__ . '/test/', - ]); + ]) + ->withSets([ + PHPUnit\Set\PHPUnitSetList::COMPOSER_BASED, + ]);
❗ Avoid sets that overlap with the rule set, for example withPhpSets(), withPreparedSets(), or withSets() with a set from Rector\Set\ValueObject\SetList. rector/rector then warns on every run that rules are registered twice, and the set enables rules that the rule set disables on purpose. Use withRules() on the rule set and withSkip() on the Rector\Configuration\RectorConfigBuilder instead.
Git
All configuration examples use the caching feature, and if you want to use it as well, you should add the cache directory to .gitignore:
+ /.build/
/vendor/
Configuring a rule set that overrides rules
💡 Optionally override rules from a rule set by passing a set of rules:
<?php declare(strict_types=1); use Ergebnis\Rector\Config; +use Ergebnis\Rector\Rules; +use Rector\CodeQuality; -$ruleSet = Config\RuleSet\Php53::create(); +$ruleSet = Config\RuleSet\Php53::create()->withRules(Config\Rules::fromArray([ + CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector::class => false, + Rules\Files\ReferenceNamespacedSymbolsRelativeToNamespacePrefixRector::class => [ + 'discoverNamespacePrefixes' => true, + 'parentNamespacePrefixes' => [ + 'Acme\\Example', + 'Symfony\\Component', + ], + ], +])); return Config\Factory::fromRuleSet($ruleSet) ->withCache(__DIR__ . '/.build/rector/') ->withPaths([ __DIR__ . '/src/', __DIR__ . '/test/', ]);
Each rule passed to withRules() replaces the entry of the rule set as a whole, or is added when the rule set does not list it (for example Ergebnis\Rector\Rules\PHPUnit\ReplaceTestAttributeWithTestPrefixRector):
falsedisables the rule;trueenables a rule that is not configurable;- an array enables a configurable rule with exactly this configuration.
Passing a class that does not exist or is not a rule for rector/rector, true for a configurable rule, an array for a rule that is not configurable, or any value other than true, false, or an array throws an Ergebnis\Rector\Config\Exception\InvalidRuleConfiguration exception.
❗ Calling withConfiguredRule() on the Rector\Configuration\RectorConfigBuilder for a rule that the rule set already configures merges the configurations, so prefer withRules() on the rule set.
Configuring a rule set that skips rules for paths
💡 Optionally skip rules for some paths with withSkip():
<?php declare(strict_types=1); use Ergebnis\Rector\Config; +use Rector\CodeQuality; $ruleSet = Config\RuleSet\Php53::create(); return Config\Factory::fromRuleSet($ruleSet) ->withCache(__DIR__ . '/.build/rector/') ->withPaths([ __DIR__ . '/src/', __DIR__ . '/test/', - ]); + ]) + ->withSkip([ + CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector::class => [ + __DIR__ . '/test/', + ], + ]);
Changelog
The maintainers of this project record notable changes to this project in a changelog.
Contributing
The maintainers of this project suggest following the contribution guide.
Code of Conduct
The maintainers of this project ask contributors to follow the code of conduct.
General Support Policy
The maintainers of this project provide limited support.
PHP Version Support Policy
This project currently supports the following PHP versions:
- PHP 7.4 (has reached its end of life on November 28, 2022)
- PHP 8.0 (has reached its end of life on November 26, 2023)
- PHP 8.1 (has reached its end of life on December 31, 2025)
- PHP 8.2
- PHP 8.3
- PHP 8.4
- PHP 8.5
- PHP 8.6
The maintainers of this project may allow installation on a PHP version as soon as they become aware of it, but do not support it before its initial release.
The maintainers of this project add support for a PHP version following its initial release and may drop support for a PHP version when it has reached its end of life.
Security Policy
This project has a security policy.
License
This project uses the MIT license.
Social
Follow @localheinz and @ergebnis on X.