Latest Version License Downloads
rector-rules is an extensible package of custom rules for Rector to automate code refactoring and enforce coding standards. It helps you maintain consistent code style and high code quality in your PHP projects through automated transformations.
composer require --dev pekral/rector-rules- Add to your
rector.phpconfiguration file:
<?php
return static function (Rector\Config\RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/vendor/pekral/rector-rules/rector.php');
};- Run Rector with your custom rules:
vendor/bin/rector process srcvendor/bin/rector process srcvendor/bin/rector process src --dry-run<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/vendor/pekral/rector-rules/rector.php');
// Your additional rules here
$rectorConfig->paths([__DIR__ . '/src']);
$rectorConfig->skip([
// Skip specific rules if needed
]);
};- Rules can be extended and customized in your
rector.phpconfiguration. - Supports PHP 8.4+.
- Easy integration with CI/CD (GitHub Actions, GitLab CI, ...).
- Includes comprehensive examples for each rule.
This package includes 150+ Rector rules covering code quality, dead code removal, PHP version upgrades, and more.
For a complete list of all included rules, see rules/rules.php.
Q: How do I add a custom rule?
A: Add it to your rector.php configuration or extend this package.
Q: How do I run Rector only on specific folders?
A: Adjust the path in the Rector command, e.g. src/, app/.
Q: How can I contribute?
A: Open an issue or pull request on GitHub.
Q: How do I see what changes Rector would make?
A: Use the --dry-run flag to preview changes without applying them.
Q: Can I skip specific rules?
A: Yes, use the skip configuration in your rector.php file.
This package is licensed under the MIT License - see the LICENSE file for details.
rector-rules is maintained by Petr Král.