-
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?
Conversation
system/HTTP/CURLRequest.php
Outdated
@@ -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) { |
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?
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.
You mean like this?
$ git diff system/HTTP/CURLRequest.php
diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php
index c78f088ff7..40e197abb5 100644
--- a/system/HTTP/CURLRequest.php
+++ b/system/HTTP/CURLRequest.php
@@ -469,8 +469,10 @@ class CURLRequest extends OutgoingRequest
*/
protected function applyBody(array $curlOptions = []): array
{
- if ($this->body !== '' && $this->body !== null) {
- $curlOptions[CURLOPT_POSTFIELDS] = (string) $this->getBody();
+ $requestBody = (string) $this->getBody();
+
+ if ($requestBody !== '') {
+ $curlOptions[CURLOPT_POSTFIELDS] = $requestBody;
}
return $curlOptions;
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
for right side, pls be more specific what we are checking against
system/HTTP/CURLRequest.php
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
right side change to is_string and !== ''?
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.
Based documentation float and string
Description
Decrease PHPStan baseline.
Checklist: