juampi92/phecks

一个用于运行自定义PHP检查的包

v1.0.2 2023-08-15 08:01 UTC

This package is auto-updated.

Last update: 2024-09-15 10:33:18 UTC


README

Phecks

文档 | 致谢

Latest Version on Packagist Downloads Per Month GitHub Tests Action Status PHP from Packagist

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

error-output

测试

composer test

致谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。