Skip to content

pekral/rector-rules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

114 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rector-rules

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages