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

PROJECT_PATH=$(dirname $(dirname $(dirname $(readlink -f "$0"))))
z40=0000000000000000000000000000000000000000

cd ${PROJECT_PATH}/vendor/nafigator
. bash-helpers/src/bash-helpers.sh
. php-qa-hooks/src/includes/pre-push.inc.sh

VERSION=0.6.4
INTERACTIVE=$(git_config_bool check.php.colors ${PROJECT_PATH})

[[ $(git_config_bool check.php.style ${PROJECT_PATH}) ]] || exit 0

parse_options ${@}
PARSE_RESULT=$?

[[ ${PARSE_RESULT} = 1 ]] && exit 1
[[ ${PARSE_RESULT} = 2 ]] && usage_help && exit 2

check_dependencies git php || exit 1

while read local_ref local_sha remote_ref remote_sha; do
	if [[ ${local_sha} != ${z40} ]]; then
		if [[ ${remote_sha} = ${z40} ]]; then
			# New branch, examine all commits
			range="$local_sha"
		else
			# Update to existing branch, examine new commits
			range="$remote_sha..$local_sha"
		fi

		while read file; do
			if [[ -e "$PROJECT_PATH/$file" ]]; then
				files="$files $file"
			fi
		done < <(get_commit_files ${range})
	fi
done

if [[ -z "$files" ]]; then
	inform 'No files for style check'
	exit 0
fi

cd ${PROJECT_PATH}
vendor/bin/phpcs -n ${files}

result=$?

status 'Code Sniffer style check' ${result}

exit ${result}<commit_msg>fix: Perform style check on unique files<commit_after>#!/usr/bin/env bash

PROJECT_PATH=$(dirname $(dirname $(dirname $(readlink -f "$0"))))
z40=0000000000000000000000000000000000000000

cd ${PROJECT_PATH}/vendor/nafigator
. bash-helpers/src/bash-helpers.sh
. php-qa-hooks/src/includes/pre-push.inc.sh

VERSION=0.6.4
INTERACTIVE=$(git_config_bool check.php.colors ${PROJECT_PATH})

[[ $(git_config_bool check.php.style ${PROJECT_PATH}) ]] || exit 0

parse_options ${@}
PARSE_RESULT=$?

[[ ${PARSE_RESULT} = 1 ]] && exit 1
[[ ${PARSE_RESULT} = 2 ]] && usage_help && exit 2

check_dependencies git php grep sort tr || exit 1

while read local_ref local_sha remote_ref remote_sha; do
	if [[ ${local_sha} != ${z40} ]]; then
		if [[ ${remote_sha} = ${z40} ]]; then
			# New branch, examine all commits
			range="$local_sha"
		else
			# Update to existing branch, examine new commits
			range="$remote_sha..$local_sha"
		fi

		while read file; do
			if [[ -e "$PROJECT_PATH/$file" ]]; then
				files="$files\n$file"
			fi
		done < <(get_commit_files ${range})
	fi
done

files=$(printf "$files" | grep . | sort -u | tr '\n' ' ')

if [[ -z "$files" ]]; then
	inform 'No files for style check'
	exit 0
fi

cd ${PROJECT_PATH}
vendor/bin/phpcs -n ${files}

result=$?

status 'Code Sniffer style check' ${result}

exit ${result}
{'fraction_non_alphanumeric': 0.1646919431279621, 'fraction_numerical': 0.045023696682464455, 'mean_word_length': 4.310272536687631, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '7100960', 'n_tokens_mistral': 1054, 'n_tokens_neox': 900, 'n_words': 238}