Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 38 additions & 24 deletions src/Curl/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ class Curl extends BaseCurl

public $curlErrorCodeConstant;
public $curlErrorCodeConstants;
public $curlOptionCodeConstants;
public $effectiveUrl;
public $rfc2616;
public $rfc6265;
public $totalTime;

private static $deferredProperties = [
'curlErrorCodeConstant',
Expand All @@ -106,6 +101,7 @@ class Curl extends BaseCurl
'rfc6265',
'totalTime',
];
private array $deferredValues = [];

/**
* Construct
Expand All @@ -120,13 +116,13 @@ public function __construct($base_url = null, $options = [])
throw new \ErrorException('cURL library is not loaded');
}

unset($this->curlErrorCodeConstant);
unset($this->curlErrorCodeConstants);
unset($this->curlOptionCodeConstants);
unset($this->effectiveUrl);
unset($this->rfc2616);
unset($this->rfc6265);
unset($this->totalTime);
unset($this->deferredValues['curlErrorCodeConstant']);
unset($this->deferredValues['curlErrorCodeConstants']);
unset($this->deferredValues['curlOptionCodeConstants']);
unset($this->deferredValues['effectiveUrl']);
unset($this->deferredValues['rfc2616']);
unset($this->deferredValues['rfc6265']);
unset($this->deferredValues['totalTime']);

$this->curl = curl_init();
$this->initialize($base_url, $options);
Expand Down Expand Up @@ -521,7 +517,7 @@ public function exec($ch = null)
if ($this->curlError) {
$curl_error_message = curl_strerror($this->curlErrorCode);

if ($this->curlErrorCodeConstant !== '') {
if (isset($this->curlErrorCodeConstant)) {
$curl_error_message .= ' (' . $this->curlErrorCodeConstant . ')';
}

Expand Down Expand Up @@ -561,9 +557,9 @@ public function exec($ch = null)
$this->errorMessage = $this->curlError ? $this->curlErrorMessage : $this->httpErrorMessage;

// Reset select deferred properties so that they may be recalculated.
unset($this->curlErrorCodeConstant);
unset($this->effectiveUrl);
unset($this->totalTime);
unset($this->deferredValues['curlErrorCodeConstant']);
unset($this->deferredValues['effectiveUrl']);
unset($this->deferredValues['totalTime']);

// Reset content-length header possibly set from a PUT or SEARCH request.
$this->unsetHeader('Content-Length');
Expand Down Expand Up @@ -1653,14 +1649,32 @@ public function __destruct()

public function __get($name)
{
$return = null;
if (
in_array($name, self::$deferredProperties, true) &&
is_callable([$this, $getter = 'get' . ucfirst($name)])
) {
$return = $this->$name = $this->$getter();
if (in_array($name, self::$deferredProperties, true)) {
if (isset($this->deferredValues[$name])) {
return $this->deferredValues[$name];
} elseif (is_callable([$this, $getter = 'get' . ucfirst($name)])) {
$this->deferredValues[$name] = $this->$getter();
return $this->deferredValues[$name];
}
}

return null;
}

public function __isset($name)
{
if (in_array($name, self::$deferredProperties, true)) {
if (isset($this->deferredValues[$name])) {
return true;
} elseif (is_callable([$this, $getter = 'get' . ucfirst($name)])) {
$this->deferredValues[$name] = $this->$getter();
return true;
} else {
return false;
}
}
return $return;

return isset($this->$name);
}

/**
Expand All @@ -1685,7 +1699,7 @@ function ($key) {
*/
private function getCurlErrorCodeConstant()
{
$curl_const_by_code = $this->curlErrorCodeConstants;
$curl_const_by_code = $this->curlErrorCodeConstants ?? [];
if (isset($curl_const_by_code[$this->curlErrorCode])) {
return $curl_const_by_code[$this->curlErrorCode];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/display_errors.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ if [[ "${error_count}" -ge 1 ]]; then
for value in "${errors[@]}"; do
((iter++))
echo -e "\nError ${iter} of ${error_count}:"
echo "${value}" | perl -pe 's/^(.*)$/\t\1/'
echo "${value}" | perl -pe 's/^(.*)$/\t\1/'
done
fi
4 changes: 2 additions & 2 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if [[ "${CI}" == "true" ]]; then
composer self-update
composer install --prefer-source --no-interaction
if [[ "${?}" -ne 0 ]]; then
echo "Error: composer install failed"
echo "Error: composer install failed"
errors+=("composer install failed")
fi
fi
Expand Down Expand Up @@ -43,5 +43,5 @@ source "display_errors.inc.sh"
if [[ "${CI_PHP_FUTURE_RELEASE}" != "true" ]]; then
exit "${#errors[@]}"
elif [[ "${#errors[@]}" -ne 0 ]]; then
echo "One or more tests failed, but allowed as the CI_PHP_FUTURE_RELEASE flag is on for PHP version ${CI_PHP_VERSION}."
echo "⚠️ One or more tests failed, but allowed as the CI_PHP_FUTURE_RELEASE flag is on for PHP version ${CI_PHP_VERSION}."
fi
16 changes: 8 additions & 8 deletions tests/run_coding_standards_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ pushd ..
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}"
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
result="$(echo -e "${tab_char}" | perl -pe 's/^(.*)$/Tab character found in \1/')"
echo "${result}"
echo "${result}"
errors+=("${result}")
fi

Expand Down Expand Up @@ -68,31 +68,31 @@ EOF
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}"
echo "${invalid_indentation}"
errors+=("${invalid_indentation}")
fi

# Prohibit trailing whitespace in php files.
trailing_whitespace=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --extended-regexp --line-number -H " +$" {} \;)
if [[ ! -z "${trailing_whitespace}" ]]; then
result="$(echo -e "${trailing_whitespace}" | perl -pe 's/^(.*)$/Trailing whitespace found in \1/')"
echo "${result}"
echo "${result}"
errors+=("${result}")
fi

# Require identical comparison operators (===, not ==) in php files.
equal=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --extended-regexp --line-number -H "[^!=]==[^=]" {} \;)
if [[ ! -z "${equal}" ]]; then
result="$(echo -e "${equal}" | perl -pe 's/^(.*)$/Non-identical comparison operator found in \1/')"
echo "${result}"
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
result="$(echo -e "${elses}" | perl -pe 's/^(.*)$/Found newline before "else" statement in \1/')"
echo "${result}"
echo "${result}"
errors+=("${result}")
fi

Expand All @@ -114,7 +114,7 @@ fi
-s \
.
if [[ "${?}" -ne 0 ]]; then
echo "Error: found PHP_CodeSniffer coding standard violation(s)"
echo "Error: found PHP_CodeSniffer coding standard violation(s)"
errors+=("found PHP_CodeSniffer coding standard violation(s)")
fi

Expand All @@ -127,7 +127,7 @@ if [[ $(echo "${CI_PHP_VERSION} < 8.4" | bc -l) -eq 1 ]]; then
vendor/bin/php-cs-fixer --version
vendor/bin/php-cs-fixer fix --ansi --config="tests/.php-cs-fixer.php" --diff --dry-run
if [[ "${?}" -ne 0 ]]; then
echo "Error: found PHP-CS-Fixer coding standard violation(s)"
echo "Error: found PHP-CS-Fixer coding standard violation(s)"
errors+=("found PHP-CS-Fixer coding standard violation(s)")
fi

Expand Down
2 changes: 1 addition & 1 deletion tests/run_phpunit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fi
--configuration "phpunit.xml" \
${phpunit_args}
if [[ "${?}" -ne 0 ]]; then
echo "Error: phpunit command failed"
echo "Error: phpunit command failed"
errors+=("phpunit command failed")
fi

Expand Down
15 changes: 12 additions & 3 deletions tests/run_static_analysis_check_phpstan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ pushd ..
set -x

if [[ $(echo "${CI_PHP_VERSION} >= 7.4" | bc -l) -eq 1 ]]; then
vendor/bin/phpstan analyse --ansi --configuration="tests/phpstan.neon" .

phpstan_args=(--ansi --configuration="tests/phpstan.neon")

# Increase memory limit on local development.
if [[ "${CI}" != "true" ]]; then
phpstan_args+=(--memory-limit=256M)
fi

vendor/bin/phpstan --version
vendor/bin/phpstan analyse "${phpstan_args[@]}" .
if [[ "${?}" -ne 0 ]]; then
echo "Error: phpstan static analysis check failed"
echo "Error: phpstan static analysis check failed"
errors+=("phpstan static analysis check failed")
fi
else
echo "Skipped running phpstan check"
echo "⚠️ Skipped running phpstan check"
fi

popd
2 changes: 1 addition & 1 deletion tests/run_static_analysis_check_psalm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else
fi

if [[ "${?}" -ne 0 ]]; then
echo "Error: psalm static analysis check failed"
echo "Error: psalm static analysis check failed"
errors+=("psalm static analysis check failed")
fi

Expand Down
2 changes: 1 addition & 1 deletion tests/run_syntax_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pushd ..
# Check syntax in php files. Use `xargs' over `find -exec' as xargs exits with a value of 1 when any command errors.
find . -type "f" -iname "*.php" ! -path "*/vendor/*" | xargs -L "1" php -l
if [[ "${?}" -ne 0 ]]; then
echo "Error: php syntax checks failed"
echo "Error: php syntax checks failed"
errors+=("php syntax checks failed")
fi

Expand Down
Loading