This package is abandoned and no longer maintained. The author suggests using the diff-sniffer/diff-sniffer package instead.

Diff Sniffer, a tool to validate coding standards only in changed line

0.5.1 2020-10-02 00:18 UTC

README

PHP Version Latest Stable Version Build Status AppVeyor Build Status Code Coverage

This tool allows you to use PHP_CodeSniffer as a pre-commit hook. The main difference from existing solutions that this one validates only changed lines of code but not the whole source tree.

Installation

Download a PHAR package of the latest release and put it somewhere within your $PATH:

$ wget https://github.com/diff-sniffer/diff-sniffer/releases/latest/download/diff-sniffer.phar
$ chmod +x diff-sniffer.phar
$ sudo cp diff-sniffer.phar /usr/local/bin/diff-sniffer

Create a pre-commit hook in a specific Git repository .

$ cd /path/to/repo
$ cat > .git/hooks/pre-commit << 'EOF'
#!/usr/bin/env bash

diff-sniffer --staged "$@"
EOF

Alternatively, you can create a global pre-commit hook for your user (see man githooks):

$ cat > ~/.config/git/hooks/pre-commit << 'EOF'
#!/usr/bin/env bash

diff-sniffer --staged "$@"
EOF

You can also install Diff Sniffer manually:

$ git clone git@github.com:diff-sniffer/diff-sniffer.git
$ cd diff-sniffer
$ composer install
$ bin/diff-sniffer --version

Continuous integration mode

Diff Sniffer can also run on a CI server and validate pull requests. For example, on Travis CI:

$ wget https://github.com/diff-sniffer/diff-sniffer/releases/latest/download/diff-sniffer.phar
$ php diff-sniffer.phar origin/$TRAVIS_BRANCH...$TRAVIS_PULL_REQUEST_SHA