Skip to content

Commit

Permalink
Add PHP syntax checks for travis-ci and pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Oct 7, 2013
1 parent c98d9c4 commit d0194bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ before_script:
- npm install -g jshint

script:
- find . \( -name '*.php' -o -name '*.inc' \) -exec php -lf {} \;
- if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then phpunit; fi
- phpcs --standard=$(if [ -e ruleset.xml ]; then echo ruleset.xml; else echo WordPress; fi) $(find . -name '*.php')
- jshint .
14 changes: 11 additions & 3 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ if [ -e .jshintrc ]; then
fi
fi

# PHP_CodeSniffer WordPress Coding Standards
if [ $(git status --porcelain | egrep "^[MARC]" | cut -c4- | egrep ".php$" | wc -l) != 0 ]; then
# Check for staged PHP files
IFS=$'\n' staged_php_files=( $(git status --porcelain | egrep '^[MARC]' | cut -c4- | egrep '.php$') )
echo $staged_php_files
if [ ${#staged_php_files[@]} != 0 ]; then
# PHP Syntax Check
for php_file in "${staged_php_files[@]}"; do
php -lf $php_file
done

# PHP_CodeSniffer WordPress Coding Standards
if command -v jshint >/dev/null 2>&1; then
phpcs_standard=$(if [ -e ruleset.xml ]; then echo ruleset.xml; else echo WordPress; fi)
phpcs -p -s -v --standard=$phpcs_standard $(git status --porcelain | egrep "^[MARC]" | cut -c4- | egrep ".php$")
phpcs -p -s -v --standard=$phpcs_standard "${staged_php_files[@]}"
else
echo "Skipping phpcs since not installed"
fi
Expand Down

0 comments on commit d0194bb

Please sign in to comment.