run:
composer.phar global require friendsofphp/php-cs-fixer
add to .bashrc or .zshrc the following path
export PATH="$PATH:$HOME/.composer/vendor/bin"
reload sources:
source ~/.bashrc
or
source ~/.zshrc
then add the following file in the .git/hooks folder of your current project
vim .git/hooks/pre-commit
#!/usr/bin/env bash
ROOT="/home/username/projects/project"
echo "########"
echo ""
echo "php-cs-fixer pre commit hook start"
echo ""
echo "########"
PHP_CS_FIXER="vendor/bin/php-cs-fixer"
HAS_PHP_CS_FIXER=false
if [ -x vendor/bin/php-cs-fixer ]; then
HAS_PHP_CS_FIXER=true
fi
if $HAS_PHP_CS_FIXER; then
$PHP_CS_FIXER fix --verbose;
fi
echo "########"
echo ""
echo "php-cs-fixer pre commit hook finish"
echo ""
echo "########"