ground/编码标准

编码标准

安装: 16

依赖: 2

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:phpcodesniffer-standard

1.0.13 2020-07-27 10:46 UTC

This package is auto-updated.

Last update: 2024-09-27 20:00:17 UTC


README

Build Status

编码标准规则集

本规范扩展并扩展了PSR-12,扩展编码风格指南,并要求遵守PSR-1,基本编码标准。

安装

  1. 通过运行以下命令安装模块:

    $ composer require --dev ground/coding-standard
  2. 将 composer 脚本添加到您的 composer.json

    "scripts": {
      "cs-check": "phpcs",
      "cs-fix": "phpcbf"
    }
  3. 在您的仓库基本路径上创建 phpcs.xml 文件

    <?xml version="1.0"?>
    <ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
    
        <arg name="basepath" value="."/>
        <arg name="cache" value=".phpcs-cache"/>
        <arg name="colors"/>
        <arg name="extensions" value="php"/>
        <arg name="parallel" value="80"/>
        
        <!-- Show progress -->
        <arg value="p"/>
    
        <!-- Paths to check -->
        <file>config</file>
        <file>src</file>
        <file>test</file>
    
        <!-- Include all rules from the Coding Standard -->
        <rule ref="CodingStandard"/>
    </ruleset>

您可以在该文件中添加或排除一些位置。有关参考资料,请参阅:https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset

用法

  • 仅运行检查

    $ composer cs-check
  • 自动修复许多 CS 问题

    $ composer cs-fix

忽略文件的某些部分

禁用文件的部分

$xmlPackage = new XMLPackage;
// phpcs:disable
$xmlPackage['error_code'] = get_default_error_code_value();
$xmlPackage->send();
// phpcs:enable

禁用特定规则

// phpcs:disable Generic.Commenting.Todo.Found
$xmlPackage = new XMLPackage;
$xmlPackage['error_code'] = get_default_error_code_value();
// TODO: Add an error message here.
$xmlPackage->send();
// phpcs:enable

忽略特定违规

$xmlPackage = new XMLPackage;
$xmlPackage['error_code'] = get_default_error_code_value();
// phpcs:ignore Generic.Commenting.Todo.Found
// TODO: Add an error message here.
$xmlPackage->send();

参考

规则可以根据您的偏好添加、排除或调整。有关如何操作的更多信息,请参阅这里