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

AI摘要
该内容为技术知识分享,介绍了名为“rector-rules”的PHP代码重构工具Composer包,用于标准化代码命名风格。文章概述了其提供的规则集、配置使用方法,并推荐了其他相关的PHP开发工具包,如php-cs-fixer-custom-fixers和phpstan-rules。

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,
        // ...
    ]);

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

本作品采用《CC 协议》,转载必须注明作者和本文链接
No practice, no gain in one's wit. 我的 Gitub
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
60
粉丝
133
喜欢
994
收藏
1354
排名:45
访问:15.5 万
私信
所有博文
社区赞助商