php-linter/php-linter

50 lines
810 B
Bash
Executable File

#!/bin/bash
DIR=`dirname $(realpath $0)`;
usage(){
echo -e "Usage: php-linter {path}\n";
}
# [1] Manage config
#========================================================#
# (1) Check argc #
if [ $# -lt 1 ]; then
usage;
echo "* Missing argument 'path'";
exit 1;
fi;
# (2) Check argument @filename #
FILENAME="`realpath $1`";
if [ ! -e $FILENAME ]; then
usage;
echo "* path '$FILENAME' doesn't exist";
exit 1;
fi;
# (3) Check file or dir #
if [ -d $FILENAME ]; then
count=0;
## {1} Exec for each file in directory ##
for phpfile in `find $FILENAME -name '*.php'`; do
count=`expr $count + 1`;
echo "($count) file $phpfile";
exec $DIR/src/linter $phpfile;
done;
else
## {2} Exec file ##
exec $DIR/src/linter $FILENAME;
fi;