Run PHP-CS-Fixer before committing code in a Git pre-commit hook.
The fixer runs quietly without making changes to your files, but will stop and print analysis upon first file that needs to be fixed. Only changed files since the last commit are checked, unless configuration files have changed, in which case the fixer runs a full check.
The hook is invoked by git commit
, and can be bypassed using the --no-verify
option:
git commit --no-verify
PHP_CS_FIXER_IGNORE_ENV=1
XDEBUG_MODE=off
Run the installer.
./install
You'll thank me later ;)
Create the hooks directory and set the Git hooks path.
mkdir ~/.githooks && git config --global core.hooksPath ~/.githooks
Download, copy, or symlink the pre-commit
script to ~/.githooks/pre-commit-php
and ensure the file is executable. The installer symlinks the script into the githooks folder.
chmod 744 ~/.githooks/pre-commit-php
Create a pre-commit script that calls the php-cs-fixer pre-commit and any local pre-commit script if it exits.
#!/bin/sh
if [ -f ~/.githooks/pre-commit-php ]; then
exec ~/.githooks/pre-commit-php
fi
if [ -f .git/hooks/pre-commit ]; then
exec .git/hooks/pre-commit
fi
Released under the GPL-3.0-or-later License.