keboola/coding-standard
Composer 安装命令:
composer require keboola/coding-standard
包简介
Keboola coding standard
README 文档
README
Versioning
- patch versions may only weaken the checks if a bug in a sniff is found
- minor versions may only update underlying coding standards with bugfixes
- major versions may introduce new sniffs, thus causing previously good builds to fail
So you should usually be fine with composer's default ^major.minor
Installation
- install via composer
composer require --dev keboola/coding-standard
- copy
example/phpcs.xmlto your project root directory. - now you can check your
srcandtestsdirectory using
vendor/bin/phpcs src tests
- create
ecs.phpin your project root directory with the following content:
<?php return ECSConfig::configure()->withSets([ __DIR__ . 'vendor/keboola/coding-standard/src/ruleset.php', ]);
-
command
vendor/bin/ecs src/will now run the checks -
command
vendor/bin/ecs --fix src/will now run the checks with automatic fixes -
add phpcs & ecs script to composer.json
{
...
"scripts": {
"phpcs": "phpcs -n --extensions=php .",
"ecs": "ecs"
}
}
Usage
composer phpcs OR composer ecs
Using standard on legacy projects
If fixing the violations is too complex, you can exclude the respective sniffs.
First you need to know which sniff is causing the violation.
composer phpcs -- -s
This will dump the sniff name along with the violation.
phpcs -n --extensions=php . "-s"
FILE: W:\keboola\http-extractor\src\Config.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
11 | ERROR | Method \Keboola\HttpExtractor\Config::getBaseUrl() does not
| | have return type hint nor @return annotation for its return
| | value.
| | (SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint)
----------------------------------------------------------------------
Then add the sniff to excludes in your phpcs.xml
<?xml version="1.0"?> <ruleset name="Custom"> <rule ref="vendor/keboola/coding-standard/ruleset.xml"> <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint" /> </rule> </ruleset>
Repeat until there are no violations.
You may take note of fixable violations and separate them visually in the file, possibly with <!-- Fixable violations below -->. That way anyone can remove one exclusion at a time, let phpcbf fix the violation, review the result and submit a PR with a fix. This will improve the chances of fixing the violations in the future.
License
MIT licensed, see LICENSE file.
keboola/coding-standard 适用场景与选型建议
keboola/coding-standard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 444.42k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 03 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 keboola/coding-standard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 keboola/coding-standard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 444.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 13
- 依赖项目数: 90
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-26