-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: prevent using empty()
on CURLRequest
#9195
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,7 +469,7 @@ protected function applyMethod(string $method, array $curlOptions): array | |
*/ | ||
protected function applyBody(array $curlOptions = []): array | ||
{ | ||
if (! empty($this->body)) { | ||
if ($this->body !== '' && $this->body !== null) { | ||
$curlOptions[CURLOPT_POSTFIELDS] = (string) $this->getBody(); | ||
} | ||
|
||
|
@@ -518,18 +518,18 @@ 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; | ||
} | ||
} | ||
|
||
// Certificate | ||
if (! empty($config['cert'])) { | ||
if (array_key_exists('cert', $config) && $config['cert']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for right side of && we can check against empty array or empty string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :532 Result of || is always true. |
||
$cert = $config['cert']; | ||
|
||
if (is_array($cert)) { | ||
|
@@ -575,7 +575,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']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for right side, pls be more specific what we are checking against |
||
$accept = $this->getHeaderLine('Accept-Encoding'); | ||
|
||
if ($accept !== '') { | ||
|
@@ -621,7 +621,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 +632,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 +650,7 @@ protected function setCURLOptions(array $curlOptions = [], array $config = []) | |
} | ||
|
||
// version | ||
if (! empty($config['version'])) { | ||
if (array_key_exists('version', $config) && $config['version']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right side change to is_string and !== ''? |
||
$version = sprintf('%.1F', $config['version']); | ||
if ($version === '1.0') { | ||
$curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just cast to string then check against empty string?