定制 pekral/rector-rules 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pekral/rector-rules

Composer 安装命令:

composer require pekral/rector-rules

包简介

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

README 文档

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.

统计信息

  • 总下载量: 16.54k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固