STAGED_FILES=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep ".*\.php$"`

if [ "$STAGED_FILES" != "" ]
then
    echo "Attempting to fix PHP files..."
    composer fix
    if [ $? != 0 ]
    then
        echo "Fix the errors before commit."
        exit 1
    else
        git add $STAGED_FILES
    fi
fi

exit $?
