#!/bin/sh

# Check for phpcs
which ./vendor/bin/phpcs
if [[ "$?" == 1 ]]; then
  echo " Please install PHPCS "
  exit 1
fi

# Check for phpstan
which ./vendor/bin/phpstan
if [[ "$?" == 1 ]]; then
  echo " Please install phpstan"
  exit 1
fi

echo " -- PHPCBF -- "
./vendor/bin/phpcbf --colors --standard=PSR12 -p --ignore=./src/Kernel.php ./src

git add .
git commit -m "PHPCBF AUTO"

echo " -- PHPCS -- "
./vendor/bin/phpcs --colors --standard=PSR12 -p --ignore=./src/Kernel.php ./src
if [[ "$?" == 1 ]]; then
  echo " PHPCS NOT OK"
  exit 1
fi

echo " -- PHPSTAN -- "
./vendor/bin/phpstan analyse ./src
if [[ "$?" == 1 ]]; then
  echo " PHPSTAN NOT OK"
  exit 1
fi

exit 0