arxeiss/coding-standards
Composer 安装命令:
composer require arxeiss/coding-standards
包简介
Custom PHP CodeSniffer ruleset
README 文档
README
Custom ruleset for PHP CodeSniffer with Slevomat sniffs. Ruleset is based on PSR2 + PSR12 with additional rules, more detailed list is below. Ruleset is possible to use with space indentation and also tabs indentation.
Installation and running
Install with composer:
composer require --dev arxeiss/coding-standards
and run CodeSniffer
./vendor/bin/phpcs --standard=./vendor/arxeiss/coding-standards/Rules/phpcs-spaces.xml .
Custom ruleset file
Better way is to create custom file phpcs.xml, with content like phpcs.example.xml. After that it is possible to run
./vendor/bin/phpcs --standard=./phpcs.xml
More info about PHP CodeSniffer can be found in the PHP CS wiki
Groups of sniffs
Package consist of multiple files based on the used sniffs.
There are 3 files basic files including all selected sniffs. Use phpcs-spaces.xml or phpcs-tabs.xml, not both. Optionally it is possible to add also phpcs-strict.xml.
- phpcs-spaces.xml - Contains all sniffs with space indentation
- phpcs-tabs.xml - Contains all sniffs with tabs indentation
- phpcs-strict.xml - Contains extra, more strict rules based on Slevomat rules
It can be handy to not include all sniffs at once, specially when migrating big project. Files above just including these partial files:
- Parts/phpcs-psr.xml - PSR2 + PSR12 standards
- Parts/phpcs-use-spaces.xml or Parts/phpcs-use-tabs.xml - Include only one file on the indentation preferences
- Parts/phpcs-generic.xml - Additional Generic rules
- Parts/phpcs-pear.xml - Additional PEAR rules
- Parts/phpcs-squiz.xml - Additional Squiz rules
- Parts/phpcs-slevomat.xml - Selected Slevomat rules
If building own ruleset based on partial files, always use Parts/phpcs-psr.xml, then Parts/phpcs-use-spaces.xml or Parts/phpcs-use-tabs.xml.
Later more additional rules can be added. See phpcs.example.xml.
Included sniffs
See SniffList, I wrote one sentence explanation for each used sniff into XML files.
Also Slevomat rules have some comments about in their repository Readme https://github.com/slevomat/coding-standard
More suggested
Check that Namespace matches file structure
This is used from my own blog in Laravel, where main folder app is BlogApp namespace.
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName"> <properties> <property name="rootNamespaces" type="array"> <element key="app" value="BlogApp"/> </property> </properties> </rule>
Since v0.11.0 mixed typehint is not required
Explanation can be found here #6
If you want to force linter to use mixed typehint, you can enable by adding this into phpcs.xml file.
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint"> <!-- Check correct type hints --> <properties> <property name="enableMixedTypeHint" value="true"/> </properties> </rule> <rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint"> <!-- Check type hint for class property --> <properties> <property name="enableMixedTypeHint" value="true"/> </properties> </rule> <rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint"> <!-- Correct return type hint --> <properties> <property name="enableMixedTypeHint" value="true"/> </properties> </rule>
arxeiss/coding-standards 适用场景与选型建议
arxeiss/coding-standards 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 38.79k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2019 年 12 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 arxeiss/coding-standards 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arxeiss/coding-standards 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 38.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 6
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2019-12-21