Search by

ergebnis / rector-config

localheinz

Provides a configuration factory and rule sets for rector/rector.

0.1.0 2026-11-25 17:33 UTC

This package is auto-updated.

Last update: 2026-11-25 17:47:36 UTC


README

Integrate Merge Release Renew

Code Coverage

Latest Stable Version Total Downloads Monthly Downloads

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:

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):

  • false disables the rule;
  • true enables 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:

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.