diff --git a/composer.json b/composer.json index 7508615..45b05ea 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ }, "require-dev": { "ext-gd": "*", + "phpcompatibility/php-compatibility": "*", "phpunit/phpunit": "*", "squizlabs/php_codesniffer": "*" }, diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index af217a7..68d2d74 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -1793,7 +1793,7 @@ class Curl public function __get($name) { $return = null; - if (in_array($name, self::$deferredProperties, true) && is_callable([$this, $getter = '__get_' . $name])) { + if (in_array($name, self::$deferredProperties, true) && is_callable([$this, $getter = '_get_' . $name])) { $return = $this->$name = $this->$getter(); } return $return; @@ -1804,7 +1804,7 @@ class Curl * * @access private */ - private function __get_effectiveUrl() + private function _get_effectiveUrl() { return $this->getInfo(CURLINFO_EFFECTIVE_URL); } @@ -1814,7 +1814,7 @@ class Curl * * @access private */ - private function __get_rfc2616() + private function _get_rfc2616() { return array_fill_keys(self::$RFC2616, true); } @@ -1824,7 +1824,7 @@ class Curl * * @access private */ - private function __get_rfc6265() + private function _get_rfc6265() { return array_fill_keys(self::$RFC6265, true); } @@ -1834,7 +1834,7 @@ class Curl * * @access private */ - private function __get_totalTime() + private function _get_totalTime() { return $this->getInfo(CURLINFO_TOTAL_TIME); } diff --git a/tests/check_coding_standards.sh b/tests/check_coding_standards.sh index 18b7b10..a830ef0 100755 --- a/tests/check_coding_standards.sh +++ b/tests/check_coding_standards.sh @@ -1,8 +1,11 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "${SCRIPT_DIR}" +# Run commands from the project root directory. +cd .. + # Enforce line ending consistency in php files. -crlf_file=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --files-with-matches $'\r' {} \;) +crlf_file=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --files-with-matches $'\r' {} \;) if [[ ! -z "${crlf_file}" ]]; then result="$(echo "${crlf_file}" | perl -pe 's/(.*)/CRLF line terminators found in \1/')" echo "${result}" @@ -10,7 +13,7 @@ if [[ ! -z "${crlf_file}" ]]; then 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" {} \;) +tab_char=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp "\t" {} \;) if [[ ! -z "${tab_char}" ]]; then result="$(echo -e "${tab_char}" | perl -pe 's/^(.*)$/Tab character found in \1/')" echo "${result}" @@ -59,14 +62,14 @@ EOF php --run "${script}" "${filename}" } export -f "find_invalid_indentation" -invalid_indentation=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec bash -c '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+=("${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 " +$" {} \;) +trailing_whitespace=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H " +$" {} \;) if [[ ! -z "${trailing_whitespace}" ]]; then result="$(echo -e "${trailing_whitespace}" | perl -pe 's/^(.*)$/Trailing whitespace found in \1/')" echo "${result}" @@ -74,7 +77,7 @@ if [[ ! -z "${trailing_whitespace}" ]]; then fi # Prohibit long lines in php files. -long_lines=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" ! -path "*/www/*" -exec awk '{print FILENAME":"NR" "length}' {} \; | awk '$2 > 120') +long_lines=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" ! -path "*/www/*" -exec awk '{print FILENAME":"NR" "length}' {} \; | awk '$2 > 120') if [[ ! -z "${long_lines}" ]]; then result="$(echo -e "${long_lines}" | perl -pe 's/^(.*)$/Long lines found in \1/')" echo "${result}" @@ -82,7 +85,7 @@ if [[ ! -z "${long_lines}" ]]; then fi # Prohibit @author in php files. -at_author=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "@author" {} \;) +at_author=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "@author" {} \;) if [[ ! -z "${at_author}" ]]; then result="$(echo -e "${at_author}" | perl -pe 's/^(.*)$/\@author found in \1/')" echo "${result}" @@ -90,7 +93,7 @@ if [[ ! -z "${at_author}" ]]; then 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" {} \;) +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 result="$(echo -e "${caps}" | perl -pe 's/^(.*)$/All caps found in \1/')" echo "${result}" @@ -98,7 +101,7 @@ if [[ ! -z "${caps}" ]]; then fi # Require identical comparison operators (===, not ==) in php files. -equal=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "[^!=]==[^=]" {} \;) +equal=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "[^!=]==[^=]" {} \;) if [[ ! -z "${equal}" ]]; then result="$(echo -e "${equal}" | perl -pe 's/^(.*)$/Non-identical comparison operator found in \1/')" echo "${result}" @@ -106,7 +109,7 @@ if [[ ! -z "${equal}" ]]; then 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" {} \;) +elseif=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "else\s+if" {} \;) if [[ ! -z "${elseif}" ]]; then result="$(echo -e "${elseif}" | perl -pe 's/^(.*)$/Found "else if" instead of "elseif" in \1/')" echo "${result}" @@ -114,7 +117,7 @@ if [[ ! -z "${elseif}" ]]; then 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+)?{' {} \;) +elses=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp '^(\s+)?else(\s+)?{' {} \;) if [[ ! -z "${elses}" ]]; then result="$(echo -e "${elses}" | perl -pe 's/^(.*)$/Found newline before "else" statement in \1/')" echo "${result}" @@ -122,7 +125,7 @@ if [[ ! -z "${elses}" ]]; then 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" {} \;) +is_null=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H -e "is_null" {} \;) if [[ ! -z "${is_null}" ]]; then result="$(echo -e "${is_null}" | perl -pe 's/^(.*)$/is_null found in \1. Replace with strict comparison (e.g. "\$x === null")./')" echo "${result}" @@ -130,8 +133,8 @@ if [[ ! -z "${is_null}" ]]; then fi # Determine which phpcs to use. -if [[ -f "../vendor/bin/phpcs" ]]; then - phpcs_to_use="../vendor/bin/phpcs" +if [[ -f "vendor/bin/phpcs" ]]; then + phpcs_to_use="vendor/bin/phpcs" else phpcs_to_use="phpcs" fi @@ -141,10 +144,10 @@ fi "${phpcs_to_use}" \ --extensions="php" \ --ignore="*/vendor/*" \ - --standard="ruleset.xml" \ + --standard="tests/ruleset.xml" \ -p \ -s \ - .. + . if [[ "${?}" -ne 0 ]]; then echo "Error: found standard violation(s)" errors+=("found standard violation(s)") diff --git a/tests/ci.sh b/tests/ci.sh index 2449625..78be95e 100755 --- a/tests/ci.sh +++ b/tests/ci.sh @@ -45,11 +45,13 @@ export PHP_CURL_CLASS_TEST_MODE_ENABLED="yes" # Start test servers. Run servers on different ports to allow simultaneous # requests without blocking. server_count=7 +declare -A pids for i in $(seq 0 $(("${server_count}" - 1))); do port=8000 (( port += $i )) - php -S "127.0.0.1:${port}" -t PHPCurlClass/ & + php -S "127.0.0.1:${port}" -t PHPCurlClass/ &> /dev/null & + pids["${i}"]="${!}" done errors=() diff --git a/tests/ruleset.xml b/tests/ruleset.xml index 0564a0e..cc281a9 100644 --- a/tests/ruleset.xml +++ b/tests/ruleset.xml @@ -1,5 +1,10 @@ + + + + +