ergebnis/rector-rules

Provides rules for rector/rector.

Maintainers

Package info

github.com/ergebnis/rector-rules

pkg:composer/ergebnis/rector-rules

Statistics

Installs: 166 676

Dependents: 26

Suggesters: 0

Stars: 9

Open Issues: 2

1.14.0 2026-03-18 11:03 UTC

README

Integrate Merge Release Renew

Code Coverage

Latest Stable Version Total Downloads Monthly Downloads

This project provides a composer package with rules for rector/rector.

Installation

Run

composer require --dev ergebnis/rector-rules

Rules

This project provides the following rules for rector/rector:

Arrays

Arrays\SortAssociativeArrayByKeyRector

This rule sorts associative arrays by key.

 <?php

 $data = [
+    'bar' => [
+        'quux' => 'quuz',
+        'quz' => 'qux',
+    ],
     'foo' => [
         'foo',
         'bar',
         'baz',
     ],
-    'bar' => [
-        'quz' => 'qux',
-        'quux' => 'quuz',
-    ],
 ];
Configuration

Faker

Faker\GeneratorPropertyFetchToMethodCallRector

This rule replaces references to deprecated properties of Faker\Generator with method calls.

 <?php

 use Faker\Factory;

 $faker = Factory::create();

- $faker->boolean;
+ $faker->boolean();

Files

Files\ReferenceNamespacedSymbolsRelativeToNamespacePrefixRector

This rule replaces references to namespaced symbols (classes, functions, constants) whose fully-qualified name starts with a namespace prefix so they are relative to that prefix.

 <?php

 namespace App;

-use Foo\Bar;
-use Foo\Bar\Baz\Qux;
+use Foo\Bar\Baz;

-new Bar\Baz\Qux\Quuz();
-new Qux\Quuz\Grauply();
-new \Foo\Bar\Baz\Qux\Quuz();
+new Baz\Qux\Quuz();
+new Baz\Qux\Quuz\Grauply();
+new Baz\Qux\Quuz();
Configuration
  • forceRelativeReferences: a boolean (default false) that forces references to be expressed relative to the namespace prefix even when the file namespace matches the prefix
  • namespacePrefixes: a list of namespace prefixes to consolidate (e.g., ['Foo\Bar\Baz', 'Example\Domain'])
  • parentNamespacePrefixes: a list of parent namespace prefixes for automatic discovery of namespace prefixes per file (e.g., ['Foo\Bar'] will discover Foo\Bar\Baz as a namespace prefix when a file references symbols under Foo\Bar\Baz)

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.

You can support the maintenance of this project by sponsoring @ergebnis.

PHP Version Support Policy

This project supports PHP versions with active and security support.

The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.

Security Policy

This project has a security policy.

License

This project uses the MIT license.

Social

Follow @localheinz and @ergebnis on Twitter.