summaryrefslogtreecommitdiffstats
path: root/site/snippets/check-php-syntax.org
blob: b21311384119345e949b4fa48b3ef55a550eb258 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#+TITLE: check-php-syntax
#+OPTIONS: toc:nil

* check-php-syntax

  A ~pre-commit~ script for git that checks if all php source files
  have proper syntax.  This catches far from all mistakes (as most are
  not syntax related, of course), but it helps sometimes.

  #+BEGIN_SRC sh :tangle yes
    #!/bin/zsh

    result=0

    cd $PWD/src
    for php in **/*.php
    do
        message=$(php -l $php)
        if [ $? -ne 0 ]
        then
            echo "$message"
        result=1
        fi
    done

    if [ $result -eq 0 ]
    then
        echo "All checked out"
    fi

    exit $result
  #+END_SRC