Skip to content

Commit fddc7d8

Browse files
committed
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 ------ ------------------------------------------------------------------------------------------------------
1 parent 9a03d0c commit fddc7d8

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

src/Curl/Curl.php

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ class Curl extends BaseCurl
9191

9292
public $curlErrorCodeConstant;
9393
public $curlErrorCodeConstants;
94-
public $curlOptionCodeConstants;
95-
public $effectiveUrl;
96-
public $rfc2616;
97-
public $rfc6265;
98-
public $totalTime;
9994

10095
private static $deferredProperties = [
10196
'curlErrorCodeConstant',
@@ -106,6 +101,7 @@ class Curl extends BaseCurl
106101
'rfc6265',
107102
'totalTime',
108103
];
104+
private array $deferredValues = [];
109105

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

123-
unset($this->curlErrorCodeConstant);
124-
unset($this->curlErrorCodeConstants);
125-
unset($this->curlOptionCodeConstants);
126-
unset($this->effectiveUrl);
127-
unset($this->rfc2616);
128-
unset($this->rfc6265);
129-
unset($this->totalTime);
119+
unset($this->deferredValues['curlErrorCodeConstant']);
120+
unset($this->deferredValues['curlErrorCodeConstants']);
121+
unset($this->deferredValues['curlOptionCodeConstants']);
122+
unset($this->deferredValues['effectiveUrl']);
123+
unset($this->deferredValues['rfc2616']);
124+
unset($this->deferredValues['rfc6265']);
125+
unset($this->deferredValues['totalTime']);
130126

131127
$this->curl = curl_init();
132128
$this->initialize($base_url, $options);
@@ -521,7 +517,7 @@ public function exec($ch = null)
521517
if ($this->curlError) {
522518
$curl_error_message = curl_strerror($this->curlErrorCode);
523519

524-
if ($this->curlErrorCodeConstant !== '') {
520+
if (isset($this->curlErrorCodeConstant)) {
525521
$curl_error_message .= ' (' . $this->curlErrorCodeConstant . ')';
526522
}
527523

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

563559
// Reset select deferred properties so that they may be recalculated.
564-
unset($this->curlErrorCodeConstant);
565-
unset($this->effectiveUrl);
566-
unset($this->totalTime);
560+
unset($this->deferredValues['curlErrorCodeConstant']);
561+
unset($this->deferredValues['effectiveUrl']);
562+
unset($this->deferredValues['totalTime']);
567563

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

16541650
public function __get($name)
16551651
{
1656-
$return = null;
1657-
if (
1658-
in_array($name, self::$deferredProperties, true) &&
1659-
is_callable([$this, $getter = 'get' . ucfirst($name)])
1660-
) {
1661-
$return = $this->$name = $this->$getter();
1652+
if (in_array($name, self::$deferredProperties, true)) {
1653+
if (isset($this->deferredValues[$name])) {
1654+
return $this->deferredValues[$name];
1655+
} elseif (is_callable([$this, $getter = 'get' . ucfirst($name)])) {
1656+
$this->deferredValues[$name] = $this->$getter();
1657+
return $this->deferredValues[$name];
1658+
}
1659+
}
1660+
1661+
return null;
1662+
}
1663+
1664+
public function __isset($name)
1665+
{
1666+
if (in_array($name, self::$deferredProperties, true)) {
1667+
if (isset($this->deferredValues[$name])) {
1668+
return true;
1669+
} elseif (is_callable([$this, $getter = 'get' . ucfirst($name)])) {
1670+
$this->deferredValues[$name] = $this->$getter();
1671+
return true;
1672+
} else {
1673+
return false;
1674+
}
16621675
}
1663-
return $return;
1676+
1677+
return isset($this->$name);
16641678
}
16651679

16661680
/**
@@ -1685,7 +1699,7 @@ function ($key) {
16851699
*/
16861700
private function getCurlErrorCodeConstant()
16871701
{
1688-
$curl_const_by_code = $this->curlErrorCodeConstants;
1702+
$curl_const_by_code = isset($this->curlErrorCodeConstants) ? $this->curlErrorCodeConstants : [];
16891703
if (isset($curl_const_by_code[$this->curlErrorCode])) {
16901704
return $curl_const_by_code[$this->curlErrorCode];
16911705
}

0 commit comments

Comments
 (0)