|
1 | | -# phpcs-diff |
2 | | -Detects violations of a defined set of coding standards based on a git diff |
| 1 | +## About |
| 2 | +phpcs-diff detects violations of a defined set of coding standards based on a git diff. It uses phpcs from the [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) project. |
| 3 | + |
| 4 | +This project is for those who have 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. |
| 5 | + |
| 6 | +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. |
| 7 | + |
| 8 | +## Usage |
| 9 | + |
| 10 | + NAME |
| 11 | + phpcs-diff - detect violations based on a git diff |
| 12 | + |
| 13 | + SYNOPSIS |
| 14 | + phpcs-diff [BASE_BRANCH]... [OPTION]... |
| 15 | + |
| 16 | + OPTIONS |
| 17 | + Here is a (very) short summary of the options available in phpcs-diff. |
| 18 | + |
| 19 | + -v |
| 20 | + increase verbosity |
| 21 | + |
| 22 | +Basic example |
| 23 | + |
| 24 | +```shell |
| 25 | +phpcs-diff develop -v |
| 26 | +``` |
| 27 | + |
| 28 | +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: |
| 29 | + |
| 30 | +```shell |
| 31 | +git diff my-current-branch develop |
| 32 | +``` |
| 33 | + |
| 34 | +## Installation |
| 35 | + |
| 36 | +The recommended method of installing this library is via [Composer](https://getcomposer.org/). |
| 37 | + |
| 38 | +### Composer |
| 39 | + |
| 40 | +Run the following command from your project root: |
| 41 | + |
| 42 | + composer global require olivertappin/phpcs-diff |
| 43 | + |
| 44 | +Alternatively, you can manually include a dependency for `olivertappin/phpcs-diff` in your `composer.json` file. For example: |
| 45 | + |
| 46 | +```json |
| 47 | +{ |
| 48 | + "require-dev": { |
| 49 | + "olivertappin/phpcs-diff": "^1.0" |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +And run `composer update olivertappin/phpcs-diff`. |
| 55 | + |
| 56 | +### Git Clone |
| 57 | +You can also download the `phpcs-diff` source and create a symlink to your `/usr/bin` directory: |
| 58 | + |
| 59 | + git clone https://github.com/olivertappin/phpcs-diff.git |
| 60 | + ln -s phpcs-diff/bin/phpcs-diff /usr/bin/phpcs-diff |
| 61 | + cd /var/www/project |
| 62 | + phpcs-diff master -v |
| 63 | + |
| 64 | +## Requirements |
| 65 | + |
| 66 | +`phpcs-diff` requires PHP version 5.6.0 or later. This project also depends on `phpcs` which is used internally to fetch the failed violations. |
| 67 | + |
| 68 | +## Contributing |
| 69 | + |
| 70 | +See [CONTRIBUTING.md](CONTRIBUTING.md) for information. |
0 commit comments