Skip to content

Instantly share code, notes, and snippets.

@akrabat
Last active August 13, 2020 14:53
Show Gist options
  • Select an option

  • Save akrabat/138951fc3f0ef85e3d5f8ff4672fbf39 to your computer and use it in GitHub Desktop.

Select an option

Save akrabat/138951fc3f0ef85e3d5f8ff4672fbf39 to your computer and use it in GitHub Desktop.

Revisions

  1. akrabat revised this gist Aug 13, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion phplint
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ set -o nounset

    # Recursively call `php -l` over the specified directories/files

    if [ -z $1 ] ; then
    if [ -z "$1" ] ; then
    printf 'Usage: %s <directory-or-file> ...\n' "$(basename "$0")"
    exit 1
    fi
  2. akrabat revised this gist Aug 13, 2020. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions phplint
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    #!/usr/bin/env bash
    set -o nounset
    set -o errexit
    set -o pipefail

    # Recursively call `php -l` over the specified directories/files

  3. akrabat created this gist Aug 13, 2020.
    47 changes: 47 additions & 0 deletions phplint
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/usr/bin/env bash
    set -o nounset
    set -o errexit
    set -o pipefail

    # Recursively call `php -l` over the specified directories/files

    if [ -z $1 ] ; then
    printf 'Usage: %s <directory-or-file> ...\n' "$(basename "$0")"
    exit 1
    fi

    ERROR=false
    SAVEIFS=$IFS
    IFS=$'\n'
    while test $# -gt 0; do
    CURRENT=${1%/}
    shift

    if [ ! -f $CURRENT ] && [ ! -d $CURRENT ] ; then
    echo "$CURRENT cannot be found"
    ERROR=true
    continue
    fi

    for FILE in $(find $CURRENT -type f -name "*.php") ; do
    OUTPUT=$(php -l "$FILE" 2> /dev/null)

    # Remove blank lines from the `php -l` output
    OUTPUT=$(echo -e "$OUTPUT" | awk 'NF')

    if [ "$OUTPUT" != "No syntax errors detected in $FILE" ] ; then
    echo -e "$FILE:"
    echo -e " ${OUTPUT//$'\n'/\\n }\n"
    ERROR=true
    fi
    done
    done

    IFS=$SAVEIFS

    if [ "$ERROR" = true ] ; then
    exit 1
    fi

    echo "No syntax errors found."
    exit 0