opsway/psr12-strict-coding-standard

现代且严格的编码规范扩展PSR12

安装次数: 97,031

依赖: 20

推荐者: 0

安全: 0

星标: 7

关注者: 18

分支: 3

开放问题: 2

语言:Shell

类型:phpcodesniffer-standard

1.1.1 2024-01-17 09:20 UTC

This package is auto-updated.

Last update: 2024-09-17 10:51:48 UTC


README

强大的代码风格检查规则集的编码规范。

本规范扩展并扩展了PSR-12,扩展编码风格指南,并要求遵守PSR-1,基本编码规范。所有额外的检查和嗅探都使用来自另一个第三方库的

  • slevomat/coding-standard
  • webimpress/coding-standard

安装

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

    composer require --dev opsway/psr12-strict-coding-standard
  2. 将composer脚本添加到您的composer.json

    "scripts": {
      "cs-check": "phpcs",
      "cs-fix": "phpcbf"
    }
  3. 运行init_phpcs.sh以在项目根目录中生成PHP_CodeSniffer规则集

    wget https://raw.githubusercontent.com/opsway/psr12-strict-modern-standart/master/init_phpcs.sh
    chmod +x ./init_phpcs.sh
    ./init_phpcs.sh

    或者,在项目根目录中创建一个规则集phpcs.xml,内容如下(注意<!-- Paths to check -->下的条目)

    <?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="10"/>
        
        <!-- Show progress -->
        <arg value="p"/>
    
        <!-- Paths to check -->
        <file>config</file>
        <file>src</file>
        <file>test</file>
    
        <!-- Include all rules from the Zend Coding Standard -->
        <rule ref="OpsWayStrictPSR12CodingStandard"/>
    </ruleset>

您可以在PHP_CodeSniffer规则集的<!-- Paths to check -->下的file元素中包含或排除相关目录。有关更多信息,请参阅PHP_CodeSniffer wiki:https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml

用法

  • 仅运行检查

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

    $ composer cs-fix

参考

规则可以根据您的偏好添加、排除或调整。有关如何操作的更多信息,请在此处找到