php-git-hooks icon indicating copy to clipboard operation
php-git-hooks copied to clipboard

Git hooks for the local repository of the PHP project

PHP Git Hooks

The Git hooks for applying in the local repository of the PHP project. Include the pre-commit hook.

Installation

Clone repository:

cd some/path
git clone https://github.com/intaro/php-git-hooks
cd php-git-hooks
php -r "readfile('https://getcomposer.org/installer');" | php
./composer.phar install

Make symlink to the pre-commit file:

cd some/symfony/project/.git/hooks
ln -s some/path/php-git-hooks/pre-commit pre-commit

pre-commit

Checks the committed files:

  • PHP Syntax on PHP-errors (with PHPLint)
  • Check code style for compliance with the standard PSR2

Based on pre-commit hook of Carlos Buenosvinos.

Example of output

$ git ci -m "commit message"
Intaro Code Quality Tool
Fetching files
Running PHPLint
Checking code style
1) src/Acme/DemoBundle/Tests/Controller/DefaultControllerTest.php (unused_use, eof_ending)

  [Exception]
  There are coding standards violations!
$ git ci -m "commit message"
Intaro Code Quality Tool
Fetching files
Running PHPLint
Checking code style
Checking code style with PHPCS
FILE: ...m/src/Acme/DemoBundle/Tests/Controller/DefaultControllerTest.php
--------------------------------------------------------------------------------
FOUND 0 ERROR(S) AND 2 WARNING(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
 197 | WARNING | Line exceeds 120 characters; contains 172 characters
 212 | WARNING | Line exceeds 120 characters; contains 128 characters
--------------------------------------------------------------------------------

  [Exception]
  There are PHPCS coding standards violations!
$ git ci -m "commit message"
Intaro Code Quality Tool
Fetching files
Running PHPLint
Checking code style
Checking code style with PHPCS
Good job dude!
[some-branch 0f5ea39] commit message
 10 files changed, 357 insertions(+), 17 deletions(-)
 create mode 120000 bin/php-cs-fixer
 create mode 120000 bin/phpcs
 create mode 100644 src/Acme/DemoBundle/Tests/Controller/DefaultControllerTest.php