interaction-design-foundation / coding-standard
IxD Foundation 标准为 PHP_CodeSniffer 提供额外的检查,补充了 Consistence 编码标准。
0.3.0
2024-07-16 23:26 UTC
Requires
- php: ^8.2
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- slevomat/coding-standard: ^8.15
- squizlabs/php_codesniffer: ^3.10
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- phpunit/phpunit: ^10.5
- vimeo/psalm: ^5.25
README
IxD Laravel 编码标准
一个侧重于严格类型的规则集。适用于应用程序和包。
安装
- 通过运行以下命令安装包:
composer require --dev interaction-design-foundation/coding-standard
- 将 composer 脚本添加到您的
composer.json
"scripts": { "cs:check": "phpcs -p -s --colors --report-full --report-summary", "cs:fix": "phpcbf -p --colors" }
- 在您的存储库基础路径上创建文件
phpcs.xml
,内容如下:
<?xml version="1.0"?> <ruleset name="My Coding Standard"> <!-- Include all rules from the IxDF Coding Standard --> <rule ref="IxDFCodingStandard"/> <!-- Paths to check --> <file>app</file> <file>config</file> <file>database</file> <file>lang</file> <file>routes</file> <file>tests</file> </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();
开发
版本控制
新规则或 Sniffs 可能不会在次要或错误修复版本中引入,而应始终基于 develop 分支,并排队等待下一个主要版本,除非被认为是对现有规则的错误修复。
参考
规则可以根据您的偏好添加、排除或修改。有关如何执行此操作的更多信息,请参阅此处
- 编码标准教程
- 配置选项
- 选择性应用规则
- 可定制的 Sniff 属性
- 其他编码标准(启发我们)