Skip to content

Instantly share code, notes, and snippets.

@andriyun
Created July 30, 2015 08:29
Show Gist options
  • Save andriyun/8e65610eab0a3e808c29 to your computer and use it in GitHub Desktop.
Save andriyun/8e65610eab0a3e808c29 to your computer and use it in GitHub Desktop.
#!/bin/sh
# PHP CodeSniffer pre-commit hook for git
# We should place it to server scripts directory to subfolder drupal-git-hooks and add hook symlink from
# repository .git directory to path/to/drupal-git-hooks
# ln -s -f /path/to/drupal-git-hooks .git/hooks
PHPCS_BIN=/usr/bin/phpcs
PHPCS_CODING_STANDARD=Drupal
PHPCS_IGNORE=
PHPCS_EXT=php,module,inc,install,test,profile,theme,js,css,info,txt
# simple check if code sniffer is set up correctly
if [ ! -x $PHPCS_BIN ]; then
echo "PHP CodeSniffer bin not found or executable -> $PHPCS_BIN"
exit 1
fi
if [ "$PHPCS_EXT" != "" ]; then
EXT="--extensions=$PHPCS_EXT"
else
EXT=""
fi
FILES=sites/modules/custom/*
OUTPUT=$($PHPCS_BIN -s --standard=$PHPCS_CODING_STANDARD $EXT $FILES)
if [ "$OUTPUT" != "" ]; then
echo OUTPUT > module-sniffer-errors.txt;
echo "Please fix PHPSniffer errors in custom modules";
exit 1
fi
FILES=sites/themes/custom/*
if [ "$FILES" == "" ]; then
exit 0
fi
OUTPUT=$($PHPCS_BIN -s --standard=$PHPCS_CODING_STANDARD $EXT $FILES)
if [ "$OUTPUT" != "" ]; then
echo OUTPUT > theme-sniffer-errors.txt;
echo "Please fix PHPSniffer errors in theme";
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment