olivertappin/phpcs-diff
Composer 安装命令:
composer require olivertappin/phpcs-diff
包简介
Detects violations of a defined coding standard based on a git diff.
README 文档
README
Installation
The recommended method of installing this library is via Composer.
Composer
Global Installation
Run the following command from your project root:
composer global require olivertappin/phpcs-diff
Manual Installation
Alternatively, you can manually include a dependency for olivertappin/phpcs-diff in your composer.json file. For example:
{
"require-dev": {
"olivertappin/phpcs-diff": "^2.0"
}
}
And run composer update olivertappin/phpcs-diff.
Git Clone
You can also download the phpcs-diff source and create a symlink to your /usr/bin directory:
git clone https://github.com/olivertappin/phpcs-diff.git
ln -s phpcs-diff/bin/phpcs-diff /usr/bin/phpcs-diff
cd /var/www/project
phpcs-diff master -v
Usage
Basic Usage
phpcs-diff <current-branch> <base-branch> -v
Where the current branch you are on is the branch you are comparing with, and develop is the base branch. In this example, phpcs-diff would run the following diff statement behind the scenes:
git diff my-current-branch develop
Please note:
- The
-vflag is optional. This returns a verbose output during processing. - The
current-branchparameter is optional. If this is not defined,phpcs-diffwill use the current commit hash viagit rev-parse --verify HEAD. - You must have a
ruleset.xmldefined in your project base directory.
After running phpcs-diff, the executable will return an output similar to the following:
########## START OF PHPCS CHECK ##########
module/Poject/src/Console/Script.php
- Line 28 (WARNING) Line exceeds 120 characters; contains 190 characters
- Line 317 (ERROR) Blank line found at end of control structure
########### END OF PHPCS CHECK ###########
Currently this is the only supported format however, I will look into adding additional formats (much like phpcs) in the near future.
Travis CI Usage
To use this as part of your CI/CD pipeline, create a script with the following:
#!/bin/bash set -e if [ ! -z "$TRAVIS_PULL_REQUEST_BRANCH" ]; then git fetch `git config --get remote.origin.url` $TRAVIS_BRANCH\:refs/remotes/origin/$TRAVIS_BRANCH; composer global require olivertappin/phpcs-diff; ~/.composer/vendor/bin/phpcs-diff $TRAVIS_BRANCH; else echo "This test does not derive from a pull-request." echo "Unable to run phpcs-diff (as there's no diff)." # Here you might consider running phpcs instead: # composer global require squizlabs/php_codesniffer; # ~/.composer/vendor/bin/phpcs . fi;
Which will allow you to run phpcs-diff against the diff of your pull-request.
Here's a sample of how this might look within Travis CI:
About
phpcs-diff detects violations of a defined set of coding standards based on a git diff. It uses phpcs from the PHP_CodeSniffer project.
This project helps by achieving the following:
- Speeds up your CI/CD pipeline validating changed files only, rather than the whole code base.
- Allows you to migrate legacy code bases that cannot risk changing everything at once to become fully compliant to a coding standard.
This executable works by only checking the changed lines, compared to the base branch, against all failed violations for those files, so you can be confident that any new or changed code will be compliant.
This will hopefully put you in a position where your codebase will become more compliant to that coding standard over time, and maybe you will find the resource to eventually change everything, and just run phpcs on its own.
Requirements
The latest version of phpcs-diff requires PHP version 5.6.0 or later.
This project also depends on squizlabs/php_codesniffer which is used internally to fetch the failed violations via phpcs.
Finally, the league/climate package is also installed. This is to deal with console output, but this dependency may be removed in a future release.
Contributing
See CONTRIBUTING.md for information.
olivertappin/phpcs-diff 适用场景与选型建议
olivertappin/phpcs-diff 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 160.24k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2018 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 olivertappin/phpcs-diff 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 olivertappin/phpcs-diff 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 160.24k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2018-08-14
