Skip to content

Commit 126c1ba

Browse files
author
Kristan Kenney
committed
Add check_php.sh
Tests PHP/HTML files for errors
1 parent e6a3199 commit 126c1ba

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/check_php.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# Original code: @jroman00 (https://gist.github.com/mathiasverraes/3096500#gistcomment-1575416)
3+
4+
error=false
5+
current=$1
6+
7+
if [ -z "$current" ]; then
8+
current="/usr/local/hestia/web/"
9+
fi
10+
11+
if [ ! -d $current ] && [ ! -f $current ] ; then
12+
echo "Invalid directory or file: $current"
13+
error=true
14+
15+
continue
16+
fi
17+
18+
echo "Checking PHP files..."
19+
for file in `find $current -type f -name "*.php"` ; do
20+
RESULTS=`php -l -n $file`
21+
22+
if [ "$RESULTS" != "No syntax errors detected in $file" ] ; then
23+
echo $RESULTS
24+
error=true
25+
fi
26+
done
27+
28+
echo "Checking HTML/PHP combined files..."
29+
for file in `find $current -type f -name "*.html"` ; do
30+
RESULTS=`php -l -n $file`
31+
32+
if [ "$RESULTS" != "No syntax errors detected in $file" ] ; then
33+
echo $RESULTS
34+
error=true
35+
fi
36+
done
37+
38+
if [ "$error" = true ] ; then
39+
exit 1
40+
else
41+
exit 0
42+
fi

0 commit comments

Comments
 (0)