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

# This include-file contains functions used in pre-push.sh.

usage_help() {
	printf "$(bold)Usage:$(clr)
  pre-push.sh [OPTIONS...]

$(bold)Options:$(clr)
  -v, --version              Show script version
  -h, --help                 Show this help message
  -d, --debug                Run program in debug mode

$(bold)Description:$(clr)
  Git-hooks intend for PHP code style checks in commits before push.

$(bold)Configuration:$(clr)
  In file $(bold).git/config$(clr) in [check.php] section you can enable
  or disable check by parameter. Same via git commands:

  git config check.php.style [false|true]

$(bold)WWW:$(clr)
  https://www.php-fig.org/psr/psr-2
  https://www.php-fig.org/psr/psr-12

"

	return 0
}

print_version() {
	printf "pre-push.sh $(bold)${VERSION}$(clr) by <NAME>\n\n"

	return 0
}

# Function returns list of changed PHP files
get_commit_files() {
	git diff-tree --no-commit-id --name-only -r $1 | egrep '(.php|.phtml)$'

	return $?
}

check_style() {
	local result=0
	local local_ref
	local local_sha
	local remote_ref
	local remote_sha
	local file
	local files
	local range

	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'
	else
		cd ${PROJECT_PATH}

		while read file; do
			git cat-file -p HEAD:${file} | vendor/bin/phpcs --colors -n --stdin-path=${file} -
		done <<< "$files"

		result=$?
<commit_msg>fix: Show phpcs sniffs in report<commit_after>#!/usr/bin/env bash

# This include-file contains functions used in pre-push.sh.

usage_help() {
	printf "$(bold)Usage:$(clr)
  pre-push.sh [OPTIONS...]

$(bold)Options:$(clr)
  -v, --version              Show script version
  -h, --help                 Show this help message
  -d, --debug                Run program in debug mode

$(bold)Description:$(clr)
  Git-hooks intend for PHP code style checks in commits before push.

$(bold)Configuration:$(clr)
  In file $(bold).git/config$(clr) in [check.php] section you can enable
  or disable check by parameter. Same via git commands:

  git config check.php.style [false|true]

$(bold)WWW:$(clr)
  https://www.php-fig.org/psr/psr-2
  https://www.php-fig.org/psr/psr-12

"

	return 0
}

print_version() {
	printf "pre-push.sh $(bold)${VERSION}$(clr) by <NAME>\n\n"

	return 0
}

# Function returns list of changed PHP files
get_commit_files() {
	git diff-tree --no-commit-id --name-only -r $1 | egrep '(.php|.phtml)$'

	return $?
}

check_style() {
	local result=0
	local local_ref
	local local_sha
	local remote_ref
	local remote_sha
	local file
	local files
	local range

	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'
	else
		cd ${PROJECT_PATH}

		while read file; do
			git cat-file -p HEAD:${file} | vendor/bin/phpcs --colors -sn --stdin-path=${file} -
		done <<< "$files"

		result=$?

{'fraction_non_alphanumeric': 0.15149136577708006, 'fraction_numerical': 0.0057561486132914706, 'mean_word_length': 3.007337526205451, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, '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': '3489607', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1351, 'n_words': 397}