Skip to content

Commit e163fac

Browse files
committed
Tidied up README.md and added Travis CI example
1 parent 8b9130e commit e163fac

4 files changed

Lines changed: 81 additions & 38 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.DS_Store
22
.idea
3-
vendor
3+
vendor

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ before_script:
2020

2121
script:
2222
- vendor/bin/phpunit --stop-on-failure
23-

README.md

Lines changed: 79 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,24 @@
11
[![Latest Version](https://img.shields.io/github/tag/olivertappin/phpcs-diff.svg?style=flat&label=release)](https://github.com/olivertappin/phpcs-diff/tags)
22
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md)
33
[![Build Status](https://travis-ci.org/olivertappin/phpcs-diff.svg?branch=master)](https://travis-ci.org/olivertappin/phpcs-diff)
4-
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/olivertappin/phpcs-diff.svg?style=flat)](https://scrutinizer-ci.com/g/olivertappin/phpcs-diff/code-structure)
54
[![Quality Score](https://img.shields.io/scrutinizer/g/olivertappin/phpcs-diff.svg?style=flat)](https://scrutinizer-ci.com/g/olivertappin/phpcs-diff)
65
[![GitHub issues](https://img.shields.io/github/issues/olivertappin/phpcs-diff.svg)](https://github.com/olivertappin/phpcs-diff/issues)
76
[![Total Downloads](https://img.shields.io/packagist/dt/olivertappin/phpcs-diff.svg?style=flat)](https://packagist.org/packages/olivertappin/phpcs-diff)
87

9-
## About
10-
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-
428
## Installation
439

4410
The recommended method of installing this library is via [Composer](https://getcomposer.org/).
4511

4612
### Composer
4713

14+
#### Global Installation
15+
4816
Run the following command from your project root:
4917

5018
composer global require olivertappin/phpcs-diff
5119

20+
#### Manual Installation
21+
5222
Alternatively, you can manually include a dependency for `olivertappin/phpcs-diff` in your `composer.json` file. For example:
5323

5424
```json
@@ -62,16 +32,90 @@ Alternatively, you can manually include a dependency for `olivertappin/phpcs-dif
6232
And run `composer update olivertappin/phpcs-diff`.
6333

6434
### Git Clone
35+
6536
You can also download the `phpcs-diff` source and create a symlink to your `/usr/bin` directory:
6637

6738
git clone https://github.com/olivertappin/phpcs-diff.git
6839
ln -s phpcs-diff/bin/phpcs-diff /usr/bin/phpcs-diff
6940
cd /var/www/project
7041
phpcs-diff master -v
7142

43+
## Usage
44+
45+
### Basic Usage
46+
47+
```shell
48+
phpcs-diff <current-branch> <base-branch> -v
49+
```
50+
51+
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:
77+
78+
```bash
79+
#!/bin/bash
80+
set -e
81+
if [ ! -z "$TRAVIS_PULL_REQUEST_BRANCH" ]; then
82+
git fetch `git config --get remote.origin.url` $TRAVIS_BRANCH\:refs/remotes/origin/$TRAVIS_BRANCH;
83+
composer global require olivertappin/phpcs-diff;
84+
~/.composer/vendor/bin/phpcs-diff $TRAVIS_BRANCH;
85+
else
86+
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+
![Travis CI Example](https://user-images.githubusercontent.com/9773040/70551339-43bcfc00-1b6f-11ea-90c7-bc660e8dea28.png)
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+
72112
## Requirements
73113

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.
75119

76120
## Contributing
77121

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
<directory suffix=".php">./tests/</directory>
1515
</testsuite>
1616
</testsuites>
17-
</phpunit>
17+
</phpunit>

0 commit comments

Comments
 (0)