pekral/rector-rules

An extensible package of custom Rector rules for automated PHP refactoring and coding standard enforcement.

0.4.2 2025-09-18 06:33 UTC

README

Latest Stable Version Total Downloads License

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

  1. 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');
};
  1. 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.