arty/php-coding-standard

PHP项目静态分析工具配置,由arty提供。

安装: 43

依赖: 0

建议者: 0

安全: 0

星标: 2

关注者: 1

分支: 0

公开问题: 2

类型:phpcodesniffer-standard

v1.0.3 2024-01-28 19:31 UTC

README

这是我每天在项目上使用的编码风格工具配置。

它包括

  • PHPCS进行代码嗅探。
  • PHPStan用于代码中的静态错误查找。
  • PHPMD进行静态性能分析(复杂度、未使用表达式、优化)。

安装

使用composer安装

composer require arty/php-coding-standard --dev

使用方法

PHPCS

在你的项目中创建一个phpcs.xml文件,并填充以下内容

<?xml version="1.0"?>
<ruleset name="Arty Coding Standard" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:noNamespaceSchemaLocation="../../vendor/squizlabs/php_codesniffer/phpcs.xsd">
    <rule ref="./vendor/arty/php-coding-standard/lib/phpcs/phpcs.xml" />
</ruleset>

运行它

$ ./vendor/bin/phpcs src

PHPStan

在你的项目中创建一个phpstan.neon文件,并填充以下内容

includes:
    - vendor/arty/php-coding-standard/lib/phpstan/phpstan.neon

运行它

$ ./vendor/bin/phpstan analyse --level=max src

PHPMD

在你的项目中创建一个phpmd.xml文件,并填充以下内容

<?xml version="1.0"?>
<ruleset name="Arty ruleset"
         xmlns="http://pmd.sf.net/ruleset/1.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
         xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
    <description>
        Arty ruleset
    </description>

    <rule ref="./vendor/arty/php-coding-standard/lib/phpmd/phpmd.xml"/>
</ruleset>

运行它

$ ./vendor/bin/phpmd src text phpmd.xml