Skip to content

PHP CodeSniffer

Harmen Janssen edited this page Jul 5, 2016 · 4 revisions

PHP CodeSniffer

We try to have a consistent codebase, and SquizLabs' CodeSniffer helps.

How to setup

  • Make sure you have the CodeSniffer installed, by running
composer require squizlabs/php_codesniffer --dev
chmod +x .git/hooks/pre-commit
  • Make sure Garp3 is at least version 3.9.11

That's it!

It's a good idea to create a .git_template directory to include the hook. That way git init will setup all your repos to automatically include the hook. See also this Stack Overflow question.

Travis integration

You can add the following to .travis.yml:

before_script:
    - chmod -R +x vendor/bin/phpcs
script:
    - if [ "$(git diff --name-only HEAD^..HEAD -- '*.php')" != "" ]; then ./vendor/bin/phpcs --standard=vendor/grrr-amsterdam/garp3/phpcs.xml --colors --encoding=utf-8 -n -p $(git diff --name-only HEAD^..HEAD -- '*.php'); fi

to test the files in your last commit.

Clone this wiki locally