pekral / rector-rules
Curated Rector rule set for PHP 8.4+ — 216 hand-picked rules in one import.
Fund package maintenance!
Requires
- php: ^8.4
- rector/rector: ^2.8.1
Requires (Dev)
- pekral/ai-olympus: dev-master
- pekral/phpcs-rules: dev-master
- pekral/phpstan-rules: dev-master
- roave/security-advisories: dev-master
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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.
Requirements
| 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.
Installation
composer require --dev pekral/rector-rules
Configuration
Import 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.
Quick start
Preview what would change, without touching a file:
vendor/bin/rector process --dry-run
Apply the changes:
vendor/bin/rector process
Warning
vendor/bin/rector process rewrites the files under the configured paths in place. Run the dry run first
and commit your work before applying.
What it does
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.
Documentation
- 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
Testing
Developing this repository needs PHP 8.5+, because the development dependencies require it.
composer install composer check
composer 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.
Upgrading
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.
Changelog
See CHANGELOG.md.
Contributing
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.
Security
See the security policy.
Credits
Maintained by Petr Král.
License
MIT — see LICENSE.