Просмотр исходного кода

Add check_php.sh

Tests PHP/HTML files for errors
Kristan Kenney 5 лет назад
Родитель
Сommit
126c1bab46
1 измененных файлов с 42 добавлено и 0 удалено
  1. 42 0
      src/check_php.sh

+ 42 - 0
src/check_php.sh

@@ -0,0 +1,42 @@
+#!/bin/bash
+# Original code: @jroman00 (https://gist.github.com/mathiasverraes/3096500#gistcomment-1575416)
+
+error=false
+current=$1
+
+if [ -z "$current" ]; then
+    current="/usr/local/hestia/web/"
+fi
+
+if [ ! -d $current ] && [ ! -f $current ] ; then
+    echo "Invalid directory or file: $current"
+    error=true
+
+    continue
+fi
+
+echo "Checking PHP files..."
+for file in `find $current -type f -name "*.php"` ; do
+    RESULTS=`php -l -n $file`
+
+    if [ "$RESULTS" != "No syntax errors detected in $file" ] ; then
+        echo $RESULTS
+        error=true
+    fi
+done
+
+echo "Checking HTML/PHP combined files..."
+for file in `find $current -type f -name "*.html"` ; do
+    RESULTS=`php -l -n $file`
+
+    if [ "$RESULTS" != "No syntax errors detected in $file" ] ; then
+        echo $RESULTS
+        error=true
+    fi
+done
+
+if [ "$error" = true ] ; then
+    exit 1
+else
+    exit 0
+fi