mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-29 19:54:49 +00:00
Fix PHPStan static analysis errors (#929)
* Increase PHPStan memory limit on local development
* Add emjois to test warnings and test errors
* Fix PHPStan static analysis errors
Error messages:
------ ------------------------------------------------------------------------------------------------------
Line src/Curl/Curl.php
------ ------------------------------------------------------------------------------------------------------
123 Cannot unset property Curl\Curl::$curlErrorCodeConstant because it might have hooks in a subclass.
🪪 unset.possiblyHookedProperty
124 Cannot unset property Curl\Curl::$curlErrorCodeConstants because it might have hooks in a subclass.
🪪 unset.possiblyHookedProperty
125 Cannot unset property Curl\Curl::$curlOptionCodeConstants because it might have hooks in a subclass.
🪪 unset.possiblyHookedProperty
126 Cannot unset property Curl\Curl::$effectiveUrl because it might have hooks in a subclass.
🪪 unset.possiblyHookedProperty
127 Cannot unset property Curl\Curl::$rfc2616 because it might have hooks in a subclass.
🪪 unset.possiblyHookedProperty
128 Cannot unset property Curl\Curl::$rfc6265 because it might have hooks in a subclass.
🪪 unset.possiblyHookedProperty
129 Cannot unset property Curl\Curl::$totalTime because it might have hooks in a subclass.
🪪 unset.possiblyHookedProperty
564 Cannot unset property Curl\Curl::$curlErrorCodeConstant because it might have hooks in a subclass.
🪪 unset.possiblyHookedProperty
565 Cannot unset property Curl\Curl::$effectiveUrl because it might have hooks in a subclass.
🪪 unset.possiblyHookedProperty
566 Cannot unset property Curl\Curl::$totalTime because it might have hooks in a subclass.
🪪 unset.possiblyHookedProperty
------ ------------------------------------------------------------------------------------------------------
This commit is contained in:
+38
-24
@@ -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',
|
||||
@@ -106,6 +101,7 @@ class Curl extends BaseCurl
|
||||
'rfc6265',
|
||||
'totalTime',
|
||||
];
|
||||
private array $deferredValues = [];
|
||||
|
||||
/**
|
||||
* Construct
|
||||
@@ -120,13 +116,13 @@ class Curl extends BaseCurl
|
||||
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);
|
||||
@@ -521,7 +517,7 @@ class Curl extends BaseCurl
|
||||
if ($this->curlError) {
|
||||
$curl_error_message = curl_strerror($this->curlErrorCode);
|
||||
|
||||
if ($this->curlErrorCodeConstant !== '') {
|
||||
if (isset($this->curlErrorCodeConstant)) {
|
||||
$curl_error_message .= ' (' . $this->curlErrorCodeConstant . ')';
|
||||
}
|
||||
|
||||
@@ -561,9 +557,9 @@ class Curl extends BaseCurl
|
||||
$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');
|
||||
@@ -1653,14 +1649,32 @@ class Curl extends BaseCurl
|
||||
|
||||
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 $return;
|
||||
|
||||
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 isset($this->$name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1685,7 +1699,7 @@ class Curl extends BaseCurl
|
||||
*/
|
||||
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];
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+2
-2
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -12,7 +12,7 @@ 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
|
||||
|
||||
@@ -20,7 +20,7 @@ fi
|
||||
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
|
||||
|
||||
@@ -68,7 +68,7 @@ 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
|
||||
|
||||
@@ -76,7 +76,7 @@ fi
|
||||
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
|
||||
|
||||
@@ -84,7 +84,7 @@ fi
|
||||
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
|
||||
|
||||
@@ -92,7 +92,7 @@ fi
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user