#!/bin/sh

PROJECTROOT=`echo $(cd ${0%/*}/../../ && pwd -P)`/
FIXER=php-cs-fixer.phar

if [ ! -e ${PROJECTROOT}${FIXER} ]; then
    echo "PHP-CS-Fixer not available, downloading to ${PROJECTROOT}${FIXER}..."
    curl -s http://cs.sensiolabs.org/get/$FIXER > ${PROJECTROOT}${FIXER}
    echo "Done. First time to check the Coding Standards."
    echo ""
fi

RES=`php ${PROJECTROOT}${FIXER} fix $PROJECTROOT --verbose`
if [ "$RES" != "" ]; then
    echo "Coding standards are not correct, cancelling your commit."
    echo ""
    echo $RES
    echo ""
    exit 1
fi
