mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-28 03:00:55 +00:00
Replace error count with error summary
This commit is contained in:
@@ -4,15 +4,17 @@ cd "${SCRIPT_DIR}"
|
||||
# Enforce line ending consistency in php files.
|
||||
crlf_file=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --files-with-matches $'\r' {} \;)
|
||||
if [[ ! -z "${crlf_file}" ]]; then
|
||||
echo "${crlf_file}" | perl -pe 's/(.*)/CRLF line terminators found in \1/'
|
||||
((errors++))
|
||||
result="$(echo "${crlf_file}" | perl -pe 's/(.*)/CRLF line terminators found in \1/')"
|
||||
echo "${result}"
|
||||
errors+=("${result}")
|
||||
fi
|
||||
|
||||
# Enforce indentation character consistency in php files.
|
||||
tab_char=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp "\t" {} \;)
|
||||
if [[ ! -z "${tab_char}" ]]; then
|
||||
echo -e "${tab_char}" | perl -pe 's/^(.*)$/Tab character found in \1/'
|
||||
((errors++))
|
||||
result="$(echo -e "${tab_char}" | perl -pe 's/^(.*)$/Tab character found in \1/')"
|
||||
echo "${result}"
|
||||
errors+=("${result}")
|
||||
fi
|
||||
|
||||
# Enforce indentation consistency in php files.
|
||||
@@ -60,63 +62,71 @@ export -f "find_invalid_indentation"
|
||||
invalid_indentation=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec bash -c 'find_invalid_indentation "{}"' \;)
|
||||
if [[ ! -z "${invalid_indentation}" ]]; then
|
||||
echo "${invalid_indentation}"
|
||||
((errors++))
|
||||
errors+=("${invalid_indentation}")
|
||||
fi
|
||||
|
||||
# Prohibit trailing whitespace in php files.
|
||||
trailing_whitespace=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H " +$" {} \;)
|
||||
if [[ ! -z "${trailing_whitespace}" ]]; then
|
||||
echo -e "${trailing_whitespace}" | perl -pe 's/^(.*)$/Trailing whitespace found in \1/'
|
||||
((errors++))
|
||||
result="$(echo -e "${trailing_whitespace}" | perl -pe 's/^(.*)$/Trailing whitespace found in \1/')"
|
||||
echo "${result}"
|
||||
errors+=("${result}")
|
||||
fi
|
||||
|
||||
# Prohibit long lines in php files.
|
||||
long_lines=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec awk '{print FILENAME":"NR" "length}' {} \; | awk '$2 > 120')
|
||||
if [[ ! -z "${long_lines}" ]]; then
|
||||
echo -e "${long_lines}" | perl -pe 's/^(.*)$/Long lines found in \1/'
|
||||
((errors++))
|
||||
result="$(echo -e "${long_lines}" | perl -pe 's/^(.*)$/Long lines found in \1/')"
|
||||
echo "${result}"
|
||||
errors+=("${result}")
|
||||
fi
|
||||
|
||||
# Prohibit @author in php files.
|
||||
at_author=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "@author" {} \;)
|
||||
if [[ ! -z "${at_author}" ]]; then
|
||||
echo -e "${at_author}" | perl -pe 's/^(.*)$/\@author found in \1/'
|
||||
((errors++))
|
||||
result="$(echo -e "${at_author}" | perl -pe 's/^(.*)$/\@author found in \1/')"
|
||||
echo "${result}"
|
||||
errors+=("${result}")
|
||||
fi
|
||||
|
||||
# Prohibit screaming caps notation in php files.
|
||||
caps=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H -e "FALSE[^']" -e "NULL" -e "TRUE" {} \;)
|
||||
if [[ ! -z "${caps}" ]]; then
|
||||
echo -e "${caps}" | perl -pe 's/^(.*)$/All caps found in \1/'
|
||||
((errors++))
|
||||
result="$(echo -e "${caps}" | perl -pe 's/^(.*)$/All caps found in \1/')"
|
||||
echo "${result}"
|
||||
errors+=("${result}")
|
||||
fi
|
||||
|
||||
# Require identical comparison operators (===, not ==) in php files.
|
||||
equal=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "[^!=]==[^=]" {} \;)
|
||||
if [[ ! -z "${equal}" ]]; then
|
||||
echo -e "${equal}" | perl -pe 's/^(.*)$/Non-identical comparison operator found in \1/'
|
||||
((errors++))
|
||||
result="$(echo -e "${equal}" | perl -pe 's/^(.*)$/Non-identical comparison operator found in \1/')"
|
||||
echo "${result}"
|
||||
errors+=("${result}")
|
||||
fi
|
||||
|
||||
# Require keyword "elseif" to be used instead of "else if" so that all control keywords look like single words.
|
||||
elseif=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "else\s+if" {} \;)
|
||||
if [[ ! -z "${elseif}" ]]; then
|
||||
echo -e "${elseif}" | perl -pe 's/^(.*)$/Found "else if" instead of "elseif" in \1/'
|
||||
((errors++))
|
||||
result="$(echo -e "${elseif}" | perl -pe 's/^(.*)$/Found "else if" instead of "elseif" in \1/')"
|
||||
echo "${result}"
|
||||
errors+=("${result}")
|
||||
fi
|
||||
|
||||
# Require both braces on else statement line; "} else {" and not "}\nelse {".
|
||||
elses=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp '^(\s+)?else(\s+)?{' {} \;)
|
||||
if [[ ! -z "${elses}" ]]; then
|
||||
echo -e "${elses}" | perl -pe 's/^(.*)$/Found newline before "else" statement in \1/'
|
||||
((errors++))
|
||||
result="$(echo -e "${elses}" | perl -pe 's/^(.*)$/Found newline before "else" statement in \1/')"
|
||||
echo "${result}"
|
||||
errors+=("${result}")
|
||||
fi
|
||||
|
||||
# Prohibit use of "is_null" and suggest using the strict comparison operator.
|
||||
is_null=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H -e "is_null" {} \;)
|
||||
if [[ ! -z "${is_null}" ]]; then
|
||||
echo -e "${is_null}" | perl -pe 's/^(.*)$/is_null found in \1. Replace with strict comparison (e.g. "\$x === null")./'
|
||||
((errors++))
|
||||
result="$(echo -e "${is_null}" | perl -pe 's/^(.*)$/is_null found in \1. Replace with strict comparison (e.g. "\$x === null")./')"
|
||||
echo "${result}"
|
||||
errors+=("${result}")
|
||||
fi
|
||||
|
||||
# Determine which phpcs to use.
|
||||
@@ -137,5 +147,5 @@ fi
|
||||
..
|
||||
if [[ "${?}" -ne 0 ]]; then
|
||||
echo "Error: found standard violation(s)"
|
||||
((errors++))
|
||||
errors+=("found standard violation(s)")
|
||||
fi
|
||||
|
||||
@@ -5,5 +5,5 @@ cd "${SCRIPT_DIR}"
|
||||
find .. -type "f" -iname "*.php" ! -path "*/vendor/*" | xargs -L "1" php -l
|
||||
if [[ "${?}" -ne 0 ]]; then
|
||||
echo "Error: php syntax checks failed"
|
||||
((errors++))
|
||||
errors+=("php syntax checks failed")
|
||||
fi
|
||||
|
||||
+15
-3
@@ -6,7 +6,7 @@ set -x
|
||||
# Use composer's phpunit and phpcs by adding composer bin directory to the path environment variable.
|
||||
export PATH="${PWD}/vendor/bin:${PATH}"
|
||||
|
||||
errors=0
|
||||
errors=()
|
||||
|
||||
source "check_syntax.sh"
|
||||
|
||||
@@ -25,9 +25,21 @@ fi
|
||||
"${phpunit_to_use}" --configuration "phpunit.xml" --debug --verbose
|
||||
if [[ "${?}" -ne 0 ]]; then
|
||||
echo "Error: phpunit command failed"
|
||||
((errors++))
|
||||
errors+=("phpunit command failed")
|
||||
fi
|
||||
|
||||
source "check_coding_standards.sh"
|
||||
|
||||
exit "${errors}"
|
||||
error_count="${#errors[@]}"
|
||||
if [[ "${error_count}" -ge 1 ]]; then
|
||||
echo -e "\nErrors found: ${error_count}"
|
||||
|
||||
iter=0
|
||||
for value in "${errors[@]}"; do
|
||||
((iter++))
|
||||
echo -e "\nError ${iter} of ${error_count}:"
|
||||
echo "${value}" | perl -pe 's/^(.*)$/\t\1/'
|
||||
done
|
||||
fi
|
||||
|
||||
exit "${#errors[@]}"
|
||||
|
||||
Reference in New Issue
Block a user