Created
July 12, 2012 07:42
-
-
Save mathiasverraes/3096500 to your computer and use it in GitHub Desktop.
Recursive PHP Lint script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
- 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I combined and added some parts:
-falseafter-pruneto omit thevendorfolder from output$(nproc)to get the actual amount of usable coresfind . -path ./vendor -prune -false -o -type f -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l -n > /dev/nullEdit: 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/nullEdit 2: More modern
xargsarguments and portablefind . -path ./vendor -prune -false -o -type f -name '*.php' -print0 | xargs -0 -L1 -P0 php -l -n > /dev/nullI ❤️ this discussion! You people are awesome!