diff --git a/phpstan-baseline.php b/phpstan-baseline.php index e775d6b9f5ef..550cab20ac4c 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -5473,12 +5473,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/HTTP/CLIRequest.php', ]; -$ignoreErrors[] = [ - // identifier: empty.notAllowed - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 10, - 'path' => __DIR__ . '/system/HTTP/CURLRequest.php', -]; $ignoreErrors[] = [ // identifier: missingType.iterableValue 'message' => '#^Method CodeIgniter\\\\HTTP\\\\CURLRequest\\:\\:applyBody\\(\\) has parameter \\$curlOptions with no value type specified in iterable type array\\.$#', diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 90157e4e05d4..e3b19a59aa19 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -356,7 +356,7 @@ public function send(string $method, string $url) // Reset our curl options so we're on a fresh slate. $curlOptions = []; - if (! empty($this->config['query']) && is_array($this->config['query'])) { + if (array_key_exists('query', $this->config) && is_array($this->config['query']) && $this->config['query'] !== []) { // This is likely too naive a solution. // Should look into handling when $url already // has query vars on it. @@ -422,7 +422,7 @@ public function send(string $method, string $url) */ protected function applyRequestHeaders(array $curlOptions = []): array { - if (empty($this->headers)) { + if ($this->headers === []) { return $curlOptions; } @@ -469,8 +469,10 @@ protected function applyMethod(string $method, array $curlOptions): array */ protected function applyBody(array $curlOptions = []): array { - if (! empty($this->body)) { - $curlOptions[CURLOPT_POSTFIELDS] = (string) $this->getBody(); + $requestBody = (string) $this->getBody(); + + if ($requestBody !== '') { + $curlOptions[CURLOPT_POSTFIELDS] = $requestBody; } return $curlOptions; @@ -518,10 +520,10 @@ protected function setResponseHeaders(array $headers = []) protected function setCURLOptions(array $curlOptions = [], array $config = []) { // Auth Headers - if (! empty($config['auth'])) { + if (array_key_exists('auth', $config) && is_array($config['auth']) && $config['auth'] !== []) { $curlOptions[CURLOPT_USERPWD] = $config['auth'][0] . ':' . $config['auth'][1]; - if (! empty($config['auth'][2]) && strtolower($config['auth'][2]) === 'digest') { + if (isset($this->config['auth'][2]) && $this->config['auth'][2] === 'digest') { $curlOptions[CURLOPT_HTTPAUTH] = CURLAUTH_DIGEST; } else { $curlOptions[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC; @@ -529,7 +531,7 @@ protected function setCURLOptions(array $curlOptions = [], array $config = []) } // Certificate - if (! empty($config['cert'])) { + if (array_key_exists('cert', $config) && $config['cert']) { $cert = $config['cert']; if (is_array($cert)) { @@ -575,7 +577,7 @@ protected function setCURLOptions(array $curlOptions = [], array $config = []) } // Decode Content - if (! empty($config['decode_content'])) { + if (array_key_exists('decode_content', $config) && $config['decode_content']) { $accept = $this->getHeaderLine('Accept-Encoding'); if ($accept !== '') { @@ -621,7 +623,7 @@ protected function setCURLOptions(array $curlOptions = [], array $config = []) $curlOptions[CURLOPT_CONNECTTIMEOUT_MS] = (float) $config['connect_timeout'] * 1000; // Post Data - application/x-www-form-urlencoded - if (! empty($config['form_params']) && is_array($config['form_params'])) { + if (array_key_exists('form_params', $config) && is_array($config['form_params']) && $config['form_params'] !== []) { $postFields = http_build_query($config['form_params']); $curlOptions[CURLOPT_POSTFIELDS] = $postFields; @@ -632,7 +634,7 @@ protected function setCURLOptions(array $curlOptions = [], array $config = []) } // Post Data - multipart/form-data - if (! empty($config['multipart']) && is_array($config['multipart'])) { + if (array_key_exists('multipart', $config) && is_array($config['multipart']) && $config['multipart'] !== []) { // setting the POSTFIELDS option automatically sets multipart $curlOptions[CURLOPT_POSTFIELDS] = $config['multipart']; } @@ -650,7 +652,7 @@ protected function setCURLOptions(array $curlOptions = [], array $config = []) } // version - if (! empty($config['version'])) { + if (array_key_exists('version', $config) && ((is_string($config['version']) && $config['version'] !== '') || (is_numeric($config['version']) && $config['version'] !== 0))) { $version = sprintf('%.1F', $config['version']); if ($version === '1.0') { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;