LoginSignup
11
12

More than 5 years have passed since last update.

PHPのシンタクスチェックを再帰的に行うシェル

Posted at

探すより作るほうが早いので作った

php-lint-recursive.sh
#!/bin/sh

echo "PHP Version: $(php -r 'echo PHP_VERSION;')"

if [ $# -eq 0 ]
then
    scan_dir=$(pwd)
else
    scan_dir=$1
fi

files=$(find $scan_dir -name "*.php")
total=0
errors=0

for file in $files
do
    OK=0
    result=$(php -l $file) && OK=1

    if [ $OK -eq 0 ]
    then
        echo "$result"
        errors=$(expr $errors + 1)
    fi

    total=$(expr $total + 1)
done

success=$(expr $total - $errors)

echo "\n$total files. $success ok. $errors errors."

if [ $errors -gt 0 ]
then
    exit 1
fi
使い方
php-lint-recursive.sh

または

php-lint-recursive.sh /path/to/dir
11
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12