Permalink
Browse files

Adds first draft of PHP error finder script.

  • Loading branch information...
1 parent ef70f0a commit 2839d9e52002a05317dbca64233e27e02596f60c @Potherca Potherca committed Aug 7, 2012
Showing with 28 additions and 0 deletions.
  1. +28 −0 util.d/php.find-syntax-errors-in-folder.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# Idea stolen from http://www.slideshare.net/nickgsuperstar/static-analysis-for-php
+
+if [ $# -lt 1 ];then
+ #@TODO: Proper usage description
+ echo 'This script expects one parameter: the directory to check for PHP (syntax) errors.'
+ exit 64
+fi
+
+DIR=$1
+
+$logFile='php-errors.log'
+
+echo '' > $logFile
+
+echo 'Will now check all files for syntax errors. This may take a while...'
+
+# @TODO: Make excluding files/folders possible (helps with vendor code and false positives)
+
+find "$DIR" -name '*.php' -exec php -l '{}' 2>&1 \; | grep -v '^No syntax errors detected in' >> $logFile
+
+cat $logFile
+
+
+# @TODO: Check file starts with either '<?' or '#!' (this includes no BOM!)
+
+#EOF

0 comments on commit 2839d9e

Please sign in to comment.