<commit_before>#!/bin/bash

set -eu

echo "********************"
echo "* start $0"
echo "********************"
echo "* repository :$CIRCLE_PROJECT_REPONAME"
echo "* branch     :$CIRCLE_BRANCH"
echo "* github url :$CIRCLE_COMPARE_URL"
echo "********************"

LIST=`git diff --name-only origin/develop | grep -e '.php$'`

echo "********************"
echo "* condition diff"
echo "********************"
if [ -z "$LIST" ]; then
    echo "********************"
    echo "* PHP file not changed."
    echo "********************"
    exit 0
fi

echo "********************"
echo "* copy PHPCompatibility"
echo "********************"
cp -R vendor/wimg/php-compatibility vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility

set +e
echo "********************"
echo "* exec check"
echo "********************"
git diff --name-only origin/develop \
    | grep -e '.php$' \
    | xargs vendor/bin/phpcs -n --standard=rules/phpcs_rules.xml --report=checkstyle --report-file=phpcs_result.xml
    
git diff --name-only origin/develop \
    | grep -e '.php$' \
    | xargs -I{} vendor/bin/phpmd {} xml rules/phpmd_rules.xml>> phpmd_result.xml
set -e

echo "********************"
echo "* save outputs"
echo "********************"
LINT_RESULT_DIR="$CIRCLE_ARTIFACTS/lint"

mkdir "$LINT_RESULT_DIR"
cp -v "phpcs_result.xml" "$LINT_RESULT_DIR/"
cp -v "phpmd_result.xml" "$LINT_RESULT_DIR/"

if [ -n "${CI_PULL_REQUEST}" ]; then
    echo "********************"
    echo "* PHP CodeSniffer"
    echo "********************"
    cat phpcs_result.xml \
        | bundle exec checkstyle_filter-git diff origin/develop \
        | bundle exec saddler report \
        --require saddler/reporter/github \
        --reporter Saddler::Reporter::Github::PullRequestReviewComment
    
    cat phpcs_result.xml
    
    echo "********************"
    echo "* PHP Mess Detector"
    echo "********************"
    cat phpmd_result.xml \
        | bundle exec pmd_translate_checkstyle_format translate \
        | bundle exec checkstyle_filter-git diff origin/develop \
        | bundle exec saddler report \
        --require saddler/reporter/github \
        --reporter Saddler::Reporter::Github::PullRequestReviewComment
    
    cat phpmd_result.xml
    
    echo "********************"
    echo "* Github Alert"
    echo "********************"
    PCS_RESULT=`cat phpcs_result.xml \
    | bundle exec checkstyle_filter-git diff origin/develop \
    | grep -o "<error [^<]*/>"`
    
    PMD_RESULT=`cat phpmd_result.xml \
    | bundle exec pmd_translate_checkstyle_format translate \
    | bundle exec checkstyle_filter-git diff origin/develop \
    | grep -o "<error [^<]*/>"`
    
    echo "*****PHPCS*****"
    echo "$PCS_RESULT"
    echo "*****PHPMD*****"
    echo "$PMD_RESULT"
    
    if [ -n "$PCS_RESULT" -o -n "$PMD_RESULT" ]; then
        exit 1
    fi
fi

echo "********************"
echo "* end   $0"
echo "********************"
<commit_msg>fix check_syntax.sh<commit_after>#!/bin/bash

set -eu

echo "********************"
echo "* start $0"
echo "********************"
echo "* repository :$CIRCLE_PROJECT_REPONAME"
echo "* branch     :$CIRCLE_BRANCH"
echo "* github url :$CIRCLE_COMPARE_URL"
echo "********************"

LIST=`git diff --name-only origin/develop | grep -e '.php$'`

echo "********************"
echo "* condition diff"
echo "********************"
if [ -z "$LIST" ]; then
    echo "********************"
    echo "* PHP file not changed."
    echo "********************"
    exit 0
fi

echo "********************"
echo "* copy PHPCompatibility"
echo "********************"
cp -R vendor/wimg/php-compatibility vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility

set +e
echo "********************"
echo "* exec check"
echo "********************"
git diff --name-only origin/develop \
    | grep -e '.php$' \
    | xargs vendor/bin/phpcs -n --standard=rules/phpcs_rules.xml --report=checkstyle --report-file=phpcs_result.xml

git diff --name-only origin/develop \
    | grep -e '.php$' \
    | xargs -I{} vendor/bin/phpmd {} xml rules/phpmd_rules.xml>> phpmd_result.xml

set -e

echo "********************"
echo "* save outputs"
echo "********************"
LINT_RESULT_DIR="$CIRCLE_ARTIFACTS/lint"

mkdir "$LINT_RESULT_DIR"
cp -v "phpcs_result.xml" "$LINT_RESULT_DIR/"
cp -v "phpmd_result.xml" "$LINT_RESULT_DIR/"

if [ -n "${CI_PULL_REQUEST}" ]; then
    echo "********************"
    echo "* PHP CodeSniffer"
    echo "********************"
    cat phpcs_result.xml \
        | bundle exec checkstyle_filter-git diff origin/develop \
        | bundle exec saddler report \
        --require saddler/reporter/github \
        --reporter Saddler::Reporter::Github::PullRequestReviewComment
    
    cat phpcs_result.xml
    
    echo "********************"
    echo "* PHP Mess Detector"
    echo "********************"
    set +e
    git diff --name-only origin/develop \
        | grep -e '.php$' \
        | xargs -I{} vendor/bin/phpmd {} xml rules/phpmd_rules.xml \
        | bundle exec pmd_translate_checkstyle_format translate \
        | bundle exec checkstyle_filter-git diff origin/develop \
        | bundle exec saddler report \
        --require saddler/reporter/github \
        --reporter Saddler::Reporter::Github::PullRequestReviewComment
    set -e
    
    cat phpmd_result.xml
    
    echo "********************"
    echo "* Github Alert"
    echo "********************"
    PCS_RESULT=`cat phpcs_result.xml \
    | bundle exec checkstyle_filter-git diff origin/develop \
    | grep -o "<error [^<]*/>"`
    
    PMD_RESULT=`git diff --name-only origin/develop \
    | grep -e '.php$' \
    | xargs -I{} vendor/bin/phpmd {} xml rules/phpmd_rules.xml \
    | bundle exec checkstyle_filter-git diff origin/develop \
    | grep -o "<error [^<]*/>"`
    
    echo "*****PHPCS*****"
    echo "$PCS_RESULT"
    echo "*****PHPMD*****"
    echo "$PMD_RESULT"
    
    if [ -n "$PCS_RESULT" -o -n "$PMD_RESULT" ]; then
        exit 1
    fi
fi

echo "********************"
echo "* end   $0"
echo "********************"

{'fraction_non_alphanumeric': 0.2600032932652725, 'fraction_numerical': 0.0013173061090070806, 'mean_word_length': 3.277464788732394, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, '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': '178419', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1941, 'n_words': 443}