-
-
Save mathiasverraes/3096500 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
for file in `find .` | |
do | |
EXTENSION="${file##*.}" | |
if [ "$EXTENSION" == "php" ] || [ "$EXTENSION" == "phtml" ] | |
then | |
RESULTS=`php -l $file` | |
if [ "$RESULTS" != "No syntax errors detected in $file" ] | |
then | |
echo $RESULTS | |
fi | |
fi | |
done |
Maybe this:
find . -type f -name '*.php' -exec php -l {} ; |grep -v "No syntax errors detected"
;)
Just redirect stdout
to /dev/null
then all you will see are the errors. There is then no need to grep stdout
.
find . -type f -name '*.php' -exec php -l {} \; >/dev/null
Something like this would be pretty useful as a GitHub Action, I reckon.
I combined and added some parts:
- @judgej redirect to /dev/null
- Add
-false
after-prune
to omit thevendor
folder from output - Add
$(nproc)
to get the actual amount of usable cores
find . -path ./vendor -prune -false -o -type f -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l -n > /dev/null
Edit: Portable version with comment from @CodeBrauer:
find . -path ./vendor -prune -false -o -type f -name '*.php' -print0 | xargs -0 -n1 -P$(nproc 2> /dev/null || sysctl -n hw.ncpu) php -l -n > /dev/null
I ❤️ this discussion! You people are awesome!
- Add
$(nproc)
to get the actual amount of usable cores
For those using macOS - nproc
is not available, but you can use sysctl -n hw.ncpu
still havent found a good (portable) version for this
redirecting the output of php -l to /dev/null also hides the parse/syntax error messages
#!/bin/sh
set -ex
find . -type f -name '*.php' ! -path './vendor/*' -exec php -l -n {} \; | (! grep -v "No syntax errors detected" )
echo 'syntax OK'
This works fine on ubuntu, but on macOS it stops the script
Thanks @JoSSte