#!/usr/bin/env bash

set -e

# PHP CS Fixer

if [ ! -f vendor/bin/php-cs-fixer ]; then
    printf "\nRunning CS Fixer ...\n\n"
    curl -L https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.2.1/php-cs-fixer.phar -o vendor/bin/php-cs-fixer
    chmod +x vendor/bin/php-cs-fixer
fi

vendor/bin/php-cs-fixer fix src tests --config=vendor/endroid/quality/.php_cs --using-cache=no || true

# PHPStan

if [ ! -f vendor/bin/phpstan ]; then
    printf "\nRunning PHPStan ...\n\n"
    curl -L https://github.com/phpstan/phpstan/releases/download/0.12.99/phpstan.phar -o vendor/bin/phpstan
    chmod +x vendor/bin/phpstan
fi

vendor/bin/phpstan analyse src --configuration=vendor/endroid/quality/phpstan.neon --level=max


# Psalm

if [ ! -f vendor/bin/psalm ]; then
    printf "\nRunning Psalm ...\n\n"
    curl -L https://github.com/vimeo/psalm/releases/download/4.11.2/psalm.phar -o vendor/bin/psalm
    chmod +x vendor/bin/psalm
fi

vendor/bin/psalm --config=vendor/endroid/quality/psalm.xml --show-info=false
