#!/usr/bin/env bash
#Thanks Leo for this.

function phpunit() {
  if [[ ! -e ./vendor/bin/phpunit ]]; then
    echo "The vendor/bin/phpunit file is missing. Did you install the dependencies?"
    exit 1
  fi

  vendor/bin/phpunit --testdox --colors
}

function php-cs-fixer() {
  if [[ ! -e ./vendor/bin/php-cs-fixer ]]; then
    echo "The vendor/bin/php-cs-fixer file is missing. Did you install the dependencies?"
    exit 1
  fi

  vendor/bin/php-cs-fixer fix -v
  #vendor/bin/php-cs-fixer fix -v --config .php_cs.legacy
}

function phplint() {
  if [[ ! -e ./vendor/bin/phplint ]]; then
    echo "The vendor/bin/phplint file is missing. Did you install the dependencies?"
    exit 1
  fi

  vendor/bin/phplint
}

function usage() {
  cat <<HEREDOC
Usage: ./run [task]
  phpunit       Run PhpUnit (not yet supported)
  php-cs-fixer  Run PHP-CS-Fixer
  phplint       Run PHPLint
HEREDOC
}

case "$1" in
  phpunit)
    phpunit
    exit 0
  ;;
  php-cs-fixer)
    php-cs-fixer
    exit 0
  ;;
  phplint)
    phplint
    exit 0
  ;;
  *)
    usage
    exit 1
  ;;
esac
