rector-rules - 提供标准化的常量、变量、函数、类、属性和方法命名以及其他 Rector 规则

rector-rules - 提供标准化的常量、变量、函数、类、属性和方法命名以及其他 Rector 规则

之前写过用 Rector 《统一规范化代码的命名风格》,现在已经整理发布为 Composer 包了。

rector-rules - 提供标准化的常量、变量、函数、类、属性和方法命名以及其他 Rector 规则。

Rector 规则总览

Rector 规则集总览

  • Guanguans\RectorRules\Set\SetList::ALL
  • Guanguans\RectorRules\Set\SetList::COMMON
  • Guanguans\RectorRules\Set\SetList::PHPBENCH
  • Guanguans\RectorRules\Set\SetList::PHPSTAN
  • Guanguans\RectorRules\Set\SetList::RECTOR

配置使用规则集和规则

use Guanguans\RectorRules\Rector\File\SortFileFunctionStmtRector;
use Guanguans\RectorRules\Rector\Name\RenameToPsrNameRector;
use PhpParser\NodeVisitor\ParentConnectingVisitor;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withSets([
        Guanguans\RectorRules\Set\SetList::ALL,
        // ...
    ])
    // ...
    ->registerDecoratingNodeVisitor(ParentConnectingVisitor::class)
    ->withConfiguredRule(RenameToPsrNameRector::class, [
        'assertMatches*Snapshot', // 排除 spatie/pest-plugin-snapshots 包的函数名称
        'beforeEach', // 排除 pestphp/pest 包的函数名称
        'PDO', // 排除 PDO 类名称
    ])
    // ...
    ->withRules([
        SortFileFunctionStmtRector::class,
        // ...
    ]);

另外推荐下其他相关类似的包

posted @ 2026-01-20 14:32  guanguans  阅读(1)  评论(0)    收藏  举报