juampi92 / phecks
一个用于运行自定义PHP检查的包
v1.0.2
2023-08-15 08:01 UTC
Requires
- php: ^8.0|^8.1|^8.2
- ext-json: *
- illuminate/console: ^8.0|^9.0|^10.0
- illuminate/contracts: ^8.0|^9.0|^10.0
- illuminate/filesystem: ^8.0|^9.0|^10.0
- illuminate/support: ^8.0|^9.0|^10.0
- roave/better-reflection: ^5.5|^6.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- nunomaduro/larastan: ^2.3|^1
- orchestra/testbench: ^5.0|^6.0|^7.0|^8.0
- phpunit/phpunit: ^9.5
README
Phecks
Phecks(代表PHP-Checks)是一个自定义检查运行器。它将在您的代码库中运行自定义检查,并生成需要修复的违规报告。
它是用来做什么的?
- 为大团队提供一个超出linting的样式指南。
- 在代码审查期间作为额外的一双眼睛使用。
- 团队根据自己的架构决策和样式指南创建自己的检查。
单独来看,Phecks不包含任何检查。您和您的团队负责根据您的架构决策定义和实现这些检查。
Phecks将为您提供易于开发和运行这些检查的结构。
安装
您可以通过composer安装此包
composer require juampi92/phecks --dev
请参阅文档中的完整安装说明。
用法
创建一个检查以确保您的团队遵守架构决策
/** * @implements Check<ReflectionClass> */ class ConsoleClassesMustBeSuffixedWithCommandCheck implements Check { public function __construct( private readonly ClassSource $source, ) {} /** * This method will get all the possible matches. */ public function getMatches(): MatchCollection { return $this->source ->directory('./app/Console') ->run() ->reject(fn (ReflectionClass $class): bool => $class->isAbstract()) ->pipe(new WhereExtendsClassFilter(\Illuminate\Console\Command::class)); } /** * processMatch will check if the matches are * actual violations, and format them properly. */ public function processMatch($match, FileMatch $file): array { if (Str::endsWith($match->getName(), 'Command')) { return []; } return [ ViolationBuilder::make()->message('Command classes must be suffixed with \'Command\''), ]; } }
在配置中添加类phecks.checks
然后运行以下命令
php artisan phecks:run
测试
composer test
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。