cn-consult/coding-standard
Composer 安装命令:
composer require cn-consult/coding-standard
包简介
Our Company-Wide Coding Standard based on PHP_CodeSniffer
README 文档
README
Our Company-Wide Coding Standard based on PHP_CodeSniffer.
Currently this is targeted for PHP-Code only, but it may also be used to sniff JS-Code or CSS, but we have no special Sniffs or Code for these languages.
Usage
To use this repository, add it as dev-dependency to your composer.json:
composer require --dev cn-consult/coding-standard:dev-master.
Aftewards create a file phpcs.xml in your project root and add the following contents:
<?xml version="1.0"?> <ruleset name="MyProject"> <description>My cool project, using the CN-Consult PHPCS standard</description> <rule ref="vendor/cn-consult/coding-standard" /> <exclude-pattern>vendor/*</exclude-pattern> </ruleset>
Afterwards you can check your code by executing:
vendor/bin/phpcs .
Development
To add new rules to our standard you should open up a youtrack-ticket and explain what you want to accomplish. You should add some examples that shows what the check should allow and/or disallow. When you get positive feedback you may implement your check. Before you implement a custom Sniff, it is a good idea to check if there perhaps already exists a Sniff that accomplishes what you want. Unfortunatly there is no single documentation that shows all available Sniffs. A good starting point may be https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties or having a look at the implemented Sniffs by name or searching after the required token in the sourcecode (for example T_FUNCTION). If there is no other way you may implement your own sniff by following this guide: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Coding-Standard-Tutorial
After you added your sniff, you can run phpcs through the provided script in tests/run-manually.sh and check if it works
and outputs the correct issues for test-files.
If all is like expected please make sure that your new sniff is tested properly.
How to add new good tests
This is really easy. Just add additional files in the examples/good/ directory
that you don't expect to generate any output, and run the unit-tests.
Your new files will be picked up automatically.
How to add new bad tests
This is a bit more involved. First add an example file in the examples/bad/ directory
that should trigger some issue. The use the tests/generate-expected-bad-output.php to verify that
the file shows the issues you expect and create an accompanying expected-file.
The generate-expected-bad-output.php will guide you through this process, just read its output.
cn-consult/coding-standard 适用场景与选型建议
cn-consult/coding-standard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.6k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cn-consult/coding-standard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cn-consult/coding-standard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 9.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-10