You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
11
-
12
-
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.
13
-
14
-
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.
15
-
16
-
## Usage
17
-
18
-
NAME
19
-
phpcs-diff - detect violations based on a git diff
20
-
21
-
SYNOPSIS
22
-
phpcs-diff [BASE_BRANCH]... [OPTION]...
23
-
24
-
OPTIONS
25
-
Here is a (very) short summary of the options available in phpcs-diff.
26
-
27
-
-v
28
-
increase verbosity
29
-
30
-
Basic example
31
-
32
-
```shell
33
-
phpcs-diff develop -v
34
-
```
35
-
36
-
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:
37
-
38
-
```shell
39
-
git diff my-current-branch develop
40
-
```
41
-
42
8
## Installation
43
9
44
10
The recommended method of installing this library is via [Composer](https://getcomposer.org/).
45
11
46
12
### Composer
47
13
14
+
#### Global Installation
15
+
48
16
Run the following command from your project root:
49
17
50
18
composer global require olivertappin/phpcs-diff
51
19
20
+
#### Manual Installation
21
+
52
22
Alternatively, you can manually include a dependency for `olivertappin/phpcs-diff` in your `composer.json` file. For example:
53
23
54
24
```json
@@ -62,16 +32,90 @@ Alternatively, you can manually include a dependency for `olivertappin/phpcs-dif
62
32
And run `composer update olivertappin/phpcs-diff`.
63
33
64
34
### Git Clone
35
+
65
36
You can also download the `phpcs-diff` source and create a symlink to your `/usr/bin` directory:
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:
52
+
53
+
```shell
54
+
git diff my-current-branch develop
55
+
```
56
+
57
+
_Please note:_
58
+
- The `-v` flag is optional. This returns a verbose output during processing.
59
+
- The `current-branch` parameter is optional. If this is not defined, phpcs-diff will use the current commit hash via `git rev-parse --verify HEAD`.
60
+
- You must have a `ruleset.xml` defined in your project base directory.
61
+
62
+
After running `phpcs-diff`, the executable will return an output similar to the following:
63
+
64
+
```
65
+
########## START OF PHPCS CHECK ##########
66
+
module/Poject/src/Console/Script.php
67
+
- Line 28 (WARNING) Line exceeds 120 characters; contains 190 characters
68
+
- Line 317 (ERROR) Blank line found at end of control structure
69
+
########### END OF PHPCS CHECK ###########
70
+
```
71
+
72
+
Currently this is the only supported format however, I will look into adding additional formats (much like `phpcs`) in the near future.
73
+
74
+
### Travis CI Usage
75
+
76
+
To use this as part of your CI/CD pipeline, create a script with the following:
echo"This test does not derive from a pull-request."
87
+
echo"Unable to run phpcs-diff (as there's no diff)."
88
+
89
+
# Here you might consider running phpcs instead:
90
+
# composer global require squizlabs/php_codesniffer;
91
+
# ~/.composer/vendor/bin/phpcs .
92
+
fi;
93
+
```
94
+
95
+
Which will allow you to run `phpcs-diff` against the diff of your pull-request.
96
+
97
+
Here's a sample of how this might look within Travis CI:
98
+
99
+

100
+
101
+
## About
102
+
`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.
103
+
104
+
This project helps by achieving the following:
105
+
- Speeds up your CI/CD pipeline validating changed files only, rather than the whole code base.
106
+
- Allows you to migrate legacy code bases that cannot risk changing everything at once to become fully compliant to a coding standard.
107
+
108
+
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.
109
+
110
+
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.
111
+
72
112
## Requirements
73
113
74
-
`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.
114
+
The latest version of `phpcs-diff` requires PHP version 5.6.0 or later.
115
+
116
+
This project also depends on `squizlabs/php_codesniffer` which is used internally to fetch the failed violations via `phpcs`.
117
+
118
+
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.
0 commit comments