0

I have a git pre-commit hook that works fine on the command line however when I try using it as a hook it gives me:

Parse error: parse error, expecting `'&'' or `"variable (T_VARIABLE)"' in /Users/jini/apps/laravel_apps/lawyermetrix/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 478

I did some research and checked that I was running everything on PHP 7

MY Pre-commit hook:

#!/bin/sh

PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`

# Determine if a file list is passed
if [ "$#" -eq 1 ]
then
    oIFS=$IFS
    IFS='
    '
    SFILES="$1"
    IFS=$oIFS
fi
SFILES=${SFILES:-$STAGED_FILES_CMD}

echo "Checking PHP Lint..."
for FILE in $SFILES
do
    php -l -d display_errors=0 $PROJECT/$FILE
    if [ $? != 0 ]
    then
        echo "Fix the error before commit."
        exit 1
    fi
    FILES="$FILES $PROJECT/$FILE"
done

if [ "$FILES" != "" ]
then
    echo "Running Coding Standards Enforcer..."
    vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 -n -p $FILES
    if [ $? != 0 ]
    then
        echo "Coding standards errors have been detected. Running phpcbf..."
        phpcbf --standard=PSR2 --encoding=utf-8 -n -p $FILES
        git add $FILES
        echo "Running Code Sniffer again..."
        phpcs --standard=PSR2 --encoding=utf-8 -n -p $FILES
        if [ $? != 0 ]
        then
            echo "Errors found not fixable automatically"
            exit 1
        fi
    fi
fi

exit $?

Now the offending line is the :

vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 -n -p $FILES

why??

kratos
  • 2,465
  • 2
  • 27
  • 45
  • Please try to reduce the size of your example by removing everything that isn't necessary to reproduce it. For example, does the same thing happen if you just run `vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 -n -p /Users/jini/apps/laravel_apps/lawyermetrix/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php` ? – that other guy Oct 06 '17 at 17:47
  • everything works on the command line. Im not testing the helpers.php file. That just seems to be the error. I was testing another file like : vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 app/Http/Controllers/LawyerController.php Works great on command line but does not when I use the same line hardcoded in pre-commit script. – kratos Oct 06 '17 at 17:53
  • I updated my answer above based on your feedback. – kratos Oct 06 '17 at 17:56
  • You're saying that `vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 app/Http/Controllers/LawyerController.php` works from the command line, but if you replace the entire contents of your pre-commit script with that line, it fails with the error message given? Does that mean that the 46 lines you posted here are not necessary to reproduce the problem? – that other guy Oct 06 '17 at 18:23
  • please refresh the page. I have updated my question. It is sometimes necessary to provide what I have done to debug this so far. – kratos Oct 06 '17 at 18:25
  • Sorry, I mistook your script for your hook. Is the entire script necessary to reproduce the problem, or can you reduce it to a single line? Posting a full script with unnecessary details is the opposite of showing what you've done to debug it. – that other guy Oct 06 '17 at 18:29
  • Sir I have merely posted the pre-commit hook code and the offending line. I think that is information that is adequate for a question. – kratos Oct 06 '17 at 18:33
  • It seems to fail due to data and circumstances not provided in your question. If you would'd like to make your question a high quality one that's likely to attract good answers and to contributes to the knowledge base of the site, consider [making a MCVE](https://stackoverflow.com/help/mcve). – that other guy Oct 06 '17 at 18:41
  • @kratos what is in your helpers.php on line 478? – masterfloda Oct 06 '17 at 20:55

0 Answers0