Skip to content

Instantly share code, notes, and snippets.

@llazzaro
Forked from Avalarion/helper.php.sh
Created May 28, 2014 12:25
Show Gist options
  • Save llazzaro/436f6a65880c64526315 to your computer and use it in GitHub Desktop.
Save llazzaro/436f6a65880c64526315 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Settings for a PHP Project
# Using:
# * PHP Lint
# *- PHP CS
# *- PHP Analyzer
# *- EmptyLines Checker
# *- Scrutinizer
# * PHPCPD
echo "\e[0;35mStarting Checking for PHP Settings\e[0m"
echo "\e[0;35m --- Will only show Errors ---\e[0m"
ERROR=0
PHPCPDLevel=10
# LINT
echo "\e[0;35m... Checking Lint\e[0m"
LINT=$(find . -name "*.php" -exec php -l {} \; 2>&1 | grep -i "Parse error")
if [ -n "$LINT" ]
then
echo $LINT
ERROR=1
fi
# PHPCS
# only list, not erroring
echo "\e[0;35m... PHP CodeSniffer\e[0m"
phpcs . --standard=TYPO3
# PHP Analyzer
# only list, not erroring
echo "\e[0;35m... Checking PHP Analyzer\e[0m"
php ~/tests/php/php-analyzer/bin/phpalizer run .
# Empty Lines
#for f in `find . -type f`; do
# for t in head tail; do
# $t -1 $f |egrep '^[ ]*$' >/dev/null && echo "blank line at the $t of $f";
# done;
#done
echo "\e[0;35m... Checking for Empty lines\e[0m"
LINES=$(ls)
if [ -n "$LINES" ]
then
echo $LINES
ERROR=1
fi
# Scrutinizer
# PHPCPD
echo "\e[0;35m... PHP CopyPaste Detection\e[0m"
echo "... -> Softlimit at least ${PHPCPDLevel}%"
PHPCPD=$(phpcpd .)
if [ `echo $PHPCPD | grep "%" | cut -d'.' -f1` -gt "$PHPCPDLevel" ]
then
echo $PHPCPD
ERROR=1
else
echo "... -> Only `echo $PHPCPD | grep "%" | cut -d'.' -f1`%"
fi
# Commit Message
echo "\e[0;35m... Git Commit Message Format\e[0m"
COMMITMESSAGE=`git log -n1`
if [ -z "`echo "$COMMITMESSAGE" | grep -E "\[(FIX|FEATURE|DOCS|OTHER)\]\s+(.*?)$"`" ]
then
echo "... -> CommitMessage Wrong: Headline missing or wrong"
ERROR=1
fi
if [ -z "`echo "$COMMITMESSAGE" | grep -E "Refs\:\s+(#\d*?).*?"`" ]
then
echo "... -> CommitMessage Wrong: Reference Missing"
ERROR=1
fi
if [ -z "`echo "$COMMITMESSAGE" | grep -E "Time\:\s+@(\d\d:\d\d)H"`" ]
then
echo "... -> CommitMessage Wrong: Time missing"
ERROR=1
fi
echo "Finished!"
exit $ERROR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment