<commit_before>#! /usr/bin/env bash

function usage {
  echo "Usage: $0 [-p path/to/php] [-c path/to/composer] [-h]" 1>&2
  exit 1
}

PHP_PATH="/usr/bin/env php"
COMPOSER_PATH="/usr/bin/env composer"

while getopts ":p:c:h" opt; do
  case $opt in
    p)
      PHP_PATH=$OPTARG
      ;;
    c)
      COMPOSER_PATH=$OPTARG
      ;;
    h)
      usage
      exit 0
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      usage
      exit 1
      ;;
    :)
      echo "Option -$OPTARG requires an argument." >&2
      usage
      exit 1
      ;;
  esac
done

STATUS=0
TEST_RES=""

function runner {
    TEST_RES=`$1`
    local TEST_RET=$?
}

function test {
    TEST_RES=`$1`
    local TEST_RET=$?
    
    if [ $TEST_RET != 0 ]
    then
        echo -e "\e[31m$2 FAILED\e[0m"
        
        echo "$TEST_RES"
        
        STATUS=$((STATUS + $3))
    else
        echo -e "\e[32m$2 SUCCESS\e[0m"
    fi
}

if [ ! -d "doc" ]
then
    mkdir -p "doc"
fi

runner "$PHP_PATH vendor/bin/phpcbf --standard=./csruleset.xml CoreBundle/"
echo "$TEST_RES" >> doc/phpcbf.txt

test "$PHP_PATH vendor/bin/phpunit" PHPUnit 100
echo "$TEST_RES" > doc/phpunit.txt

test "$PHP_PATH vendor/bin/phpcs --standard=./csruleset.xml CoreBundle/" PHPCS 100
echo "$TEST_RES" > doc/phpcs.txt

test "$COMPOSER_PATH validate" COMPOSER 100
echo "$TEST_RES" > doc/composer.txt

test "$PHP_PATH vendor/bin/phpmd CoreBundle/ text ./phpmd.xml" PHPMD 100
echo "$TEST_RES" > doc/phpmd.txt

test "$PHP_PATH vendor/bin/phpcpd CoreBundle/" PHPCPD 1
echo "$TEST_RES" > doc/phpcpd.txt

test "$PHP_PATH vendor/bin/phpmetrics --report-html=doc/metrics CoreBundle/" PHPMETRICS 1
echo "$TEST_RES" > doc/phpmetrics.txt

if [ "$STATUS" -eq 0 ]
then
    echo -e "\n\e[42m"
    echo -e "\e[30mTHE STATUS IS STABLE\n\e[0m\n\e[49m"
elif [ "$STATUS" -lt 100 ]
then
    echo -e "\n\e[43m"
    echo -e "\e[30mTHE STATUS IS UNSTABLE\n\e[0m\n\e[49m"
else
    echo -e "\n\e[41m"<commit_msg>Update tests to cover complete system<commit_after>#! /usr/bin/env bash

function usage {
  echo "Usage: $0 [-p path/to/php] [-c path/to/composer] [-h]" 1>&2
  exit 1
}

PHP_PATH="/usr/bin/env php"
COMPOSER_PATH="/usr/bin/env composer"

while getopts ":p:c:h" opt; do
  case $opt in
    p)
      PHP_PATH=$OPTARG
      ;;
    c)
      COMPOSER_PATH=$OPTARG
      ;;
    h)
      usage
      exit 0
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      usage
      exit 1
      ;;
    :)
      echo "Option -$OPTARG requires an argument." >&2
      usage
      exit 1
      ;;
  esac
done

STATUS=0
TEST_RES=""

function runner {
    TEST_RES=`$1`
    local TEST_RET=$?
}

function test {
    TEST_RES=`$1`
    local TEST_RET=$?
    
    if [ $TEST_RET != 0 ]
    then
        echo -e "\e[31m$2 FAILED\e[0m"
        
        echo "$TEST_RES"
        
        STATUS=$((STATUS + $3))
    else
        echo -e "\e[32m$2 SUCCESS\e[0m"
    fi
}

if [ ! -d "doc" ]
then
    mkdir -p "doc"
fi

runner "$PHP_PATH vendor/bin/phpcbf --standard=./csruleset.xml CoreBundle/"
echo "$TEST_RES" >> doc/phpcbf.txt

test "$PHP_PATH vendor/bin/phpunit" PHPUnit 100
echo "$TEST_RES" > doc/phpunit.txt

test "$PHP_PATH vendor/bin/phpcs --standard=./csruleset.xml CoreBundle/" PHPCS 100
echo "$TEST_RES" > doc/phpcs.txt

test "$COMPOSER_PATH validate" COMPOSER 100
echo "$TEST_RES" > doc/composer.txt

test "$PHP_PATH vendor/bin/phpmd CoreBundle/ text ./phpmd.xml" PHPMD 100
echo "$TEST_RES" > doc/phpmd.txt

test "$PHP_PATH vendor/bin/phpcpd CoreBundle/" PHPCPD 1
echo "$TEST_RES" > doc/phpcpd.txt

test "$PHP_PATH vendor/bin/phpmetrics --report-html=doc/metrics ." PHPMETRICS 1
echo "$TEST_RES" > doc/phpmetrics.txt

if [ "$STATUS" -eq 0 ]
then
    echo -e "\n\e[42m"
    echo -e "\e[30mTHE STATUS IS STABLE\n\e[0m\n\e[49m"
elif [ "$STATUS" -lt 100 ]
then
    echo -e "\n\e[43m"
    echo -e "\e[30mTHE STATUS IS UNSTABLE\n\e[0m\n\e[49m"
else
    echo -e "\n\e[41m"
{'fraction_non_alphanumeric': 0.1539250897896357, 'fraction_numerical': 0.028732683427398667, 'mean_word_length': 2.4443462897526502, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1381965', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1567, 'n_words': 383}