egeniq / php-coding-standard
Egeniq 编码规范是我们公司在 Egeniq 使用的一组 PHPCS 规则,它基于 Doctrine 项目。
1.2.0
2022-09-14 09:24 UTC
Requires
- php: >=7.4
- dealerdirect/phpcodesniffer-composer-installer: ^0.7
- slevomat/coding-standard: ^8.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-09-14 13:43:51 UTC
README
Egeniq 编码规范是我们公司在 Egeniq 使用的一组 PHP_CodeSniffer 规则。该规范在很大程度上基于 Doctrine 编码规范。
安装
您可以将 Egeniq 编码规范作为 composer 依赖项安装到您的特定项目中。只需运行以下命令将其添加到您的项目中:
php composer require --dev egeniq/php-coding-standard
然后您可以使用它如下:
vendor/bin/phpcs --standard=Egeniq /path/to/some/file/to/sniff.php
您还可以使用 phpcbf 进行自动修复。
vendor/bin/phpcbf --standard=Egeniq /path/to/some/file/to/sniff.php
项目级规则集
要为您的项目启用 Egeniq 编码规范,请创建一个 phpcs.xml.dist 文件,内容如下:
<?xml version="1.0"?> <ruleset> <arg name="basepath" value="."/> <arg name="extensions" value="php"/> <arg name="parallel" value="80"/> <arg name="cache" value=".phpcs-cache"/> <arg name="colors"/> <!-- Ignore warnings, show progress of the run and show sniff names --> <arg value="nps"/> <!-- Directories to be checked --> <file>app</file> <file>tests</file> <!-- Include full Egeniq coding standard --> <rule ref="Egeniq"> <!-- sniffs to exclude --> <!-- by default strict types are required, but if you wish to disable this, exclude the following sniff: <exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes"/> --> </rule> </ruleset>
这将直接启用 Egeniq 编码规范,包括所有默认包含的规则。从现在起,您只需运行 vendor/bin/phpcs
和 vendor/bin/phpcbf
而无需任何参数即可 🙌。