whatwedo/php-coding-standard

whatwedo的默认PHP编码标准

v1.2.5 2024-05-23 16:43 UTC

README

Latest Stable Version

PhpCodingStandard

本项目是一套编码标准规则集,我们正在whatwedo中使用。它基于Simplify/EasyCodingStandard

安装

我们建议使用Composer来安装此项目

composer require whatwedo/php-coding-standard

使用方法

无自定义配置

您可以使用以下命令之一运行检查,而不使用特定于项目的配置

vendor/bin/ecs check SRC_DIRECTORY --config vendor/whatwedo/php-coding-standard/config/whatwedo-symfony.php # Symfony projects
vendor/bin/ecs check SRC_DIRECTORY --config vendor/whatwedo/php-coding-standard/config/whatwedo-wordpress.php # WordPress projects
vendor/bin/ecs check SRC_DIRECTORY --config vendor/whatwedo/php-coding-standard/config/whatwedo-common.php # Common PHP projects

自定义配置

如果您想添加额外的检查器或排除文件,您必须在自己的项目根目录中创建一个ecs.php文件。

<?php
declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ECSConfig $ecsConfig): void {
    /*
    // Remove rules with $ecsConfig->skip()
    $ecsConfig->skip([
        SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff::class => null,

        // Explicitly remove some rules in a specific files
        PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer::class => [
            __DIR__ . '/PATH/FILE.php'
        ],
    ]);
    */

    // This need to come last
    $ecsConfig->sets([__DIR__ . '/vendor/whatwedo/php-coding-standard/config/whatwedo-common.php']);
};

然后运行以下命令

vendor/bin/ecs check SRC_DIRECTORY

要自动修复某些问题,请添加--fix

有关其他配置选项,请参阅Simplify/EasyCodingStandard

依赖项

许可

此包受MIT许可。请参阅包中的完整许可LICENSE