opsway/ psr12-strict-coding-standard
现代且严格的编码规范扩展PSR12
1.1.1
2024-01-17 09:20 UTC
Requires
- php: ^8.0
- dealerdirect/phpcodesniffer-composer-installer: ~0.7 || ^1.0
- slevomat/coding-standard: ^7.0 || ^8.0
- squizlabs/php_codesniffer: ^3.6 || ^4.0
- webimpress/coding-standard: ^1.2
README
强大的代码风格检查规则集的编码规范。
本规范扩展并扩展了PSR-12,扩展编码风格指南,并要求遵守PSR-1,基本编码规范。所有额外的检查和嗅探都使用来自另一个第三方库的
- slevomat/coding-standard
- webimpress/coding-standard
安装
-
通过运行以下命令安装模块
composer require --dev opsway/psr12-strict-coding-standard
-
将composer脚本添加到您的
composer.json
"scripts": { "cs-check": "phpcs", "cs-fix": "phpcbf" }
-
运行
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
参考
规则可以根据您的偏好添加、排除或调整。有关如何操作的更多信息,请在此处找到