A curated Rector rule set for PHP 8.4+ projects: one import registers 216 hand-picked rules. Every other rule Rector ships is recorded in this repository as deliberately left out, and a CI guard fails until someone decides about each rule a new Rector release adds.
| Version | |
|---|---|
| PHP | ^8.4 |
rector/rector |
^2.8.4 |
rector/rector is the only runtime dependency. Developing this repository needs PHP 8.5+ — see
Testing.
composer require --dev pekral/rector-rulesImport the package's rector.php in your project's rector.php and set the paths Rector should process:
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withPaths([__DIR__ . '/src'])
->withSets([__DIR__ . '/vendor/pekral/rector-rules/rector.php']);The closure style ($rectorConfig->import(...)) works too. The set raises Rector's parallel process timeout
to 180 s and leaves the worker count at Rector's default. Skipping rules, combining this set with other sets,
and overriding the timeout are covered in docs/configuration.md.
Preview what would change, without touching a file:
vendor/bin/rector process --dry-runApply the changes:
vendor/bin/rector processWarning
vendor/bin/rector process rewrites the files under the configured paths in place. Run the dry run first
and commit your work before applying.
216 rules, grouped by what they do:
| Area | Rules | What it covers |
|---|---|---|
TypeDeclaration |
50 | Infer and add native parameter, property, and return types |
CodeQuality |
44 | Simplify conditions, loops, and expressions |
DeadCode |
42 | Remove unreachable code, unused variables, and redundant docblocks |
PHPUnit |
19 | Modernise test syntax, attributes, and assertions |
TypeDeclarationDocblocks |
14 | Narrow array docblocks that no native type can express |
Php53 – Php86 |
36 | Upgrade syntax to newer PHP versions |
| Other | 11 | Privatization, CodingStyle, EarlyReturn, Visibility |
The set is opinionated: turn off any rule that does not fit your codebase with withSkip(). The
authoritative list is rules/rules.php, a plain array of rule class names.
- Configuration — closure style, skipping rules, combining with Rector's own and third-party sets, the parallel timeout
- How the set is curated — the ignore list, the missing-rule guard, why a rule is not included, and which files the package ships
- Rector documentation and the Rector rule catalog
- Discussions
Developing this repository needs PHP 8.5+, because the development dependencies require it.
composer install
composer checkcomposer check runs the code style check, a Rector dry run on this repository's own sources, and the
missing-rule guard. The other development commands are listed in CONTRIBUTING.md.
Most releases so far have changed the set, patch releases included, so an upgrade can make Rector rewrite
more of your code than before. Run vendor/bin/rector process --dry-run after upgrading and read
UPGRADING.md.
See CHANGELOG.md.
To propose a change, open an Enable a rule or Disable a rule issue, or see CONTRIBUTING.md. Participation is governed by the code of conduct.
See the security policy.
Maintained by Petr Král.
MIT — see LICENSE.