pekral / rector-rules
An extensible package of custom Rector rules for automated PHP refactoring and coding standard enforcement.
Fund package maintenance!
pekral
Installs: 3 349
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.4
- rector/rector: ^2.1.7
Requires (Dev)
- pekral/phpcs-rules: ^0.4.2
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2025-09-18 06:47:50 UTC
README
Latest Version License Downloads
๐ Introduction
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.
๐ฆ Installation
composer require --dev pekral/rector-rules
โ๏ธ Usage
- Add to your
rector.php
configuration 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 src
๐ Usage Examples
Code refactoring
vendor/bin/rector process src
Dry-run (preview changes)
vendor/bin/rector process src --dry-run
Example configuration (rector.php)
<?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 ]); };
โ๏ธ Configuration
- Rules can be extended and customized in your
rector.php
configuration. - Supports PHP 8.4+.
- Easy integration with CI/CD (GitHub Actions, GitLab CI, ...).
- Includes comprehensive examples for each rule.
๐ Included Rules
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.
โ FAQ
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.
๐ Further Resources
๐ License
This package is licensed under the MIT License - see the LICENSE file for details.
About
rector-rules is maintained by Petr Krรกl.