Skip to content
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

CS: remove Yoda conditions #417

Merged
merged 1 commit into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions library/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public static function request($url, $headers = array(), $data = array(), $type
}
}
else {
$need_ssl = (0 === stripos($url, 'https://'));
$need_ssl = (stripos($url, 'https://') === 0);
$capabilities = array('ssl' => $need_ssl);
$transport = self::get_transport($capabilities);
}
Expand Down Expand Up @@ -898,7 +898,7 @@ public static function compatible_gzinflate($gz_data) {
}
}
$decompressed = self::compatible_gzinflate(substr($gz_data, $i));
if (false !== $decompressed) {
if ($decompressed !== false) {
return $decompressed;
}
}
Expand All @@ -919,18 +919,18 @@ public static function compatible_gzinflate($gz_data) {
// First 2 bytes should be divisible by 0x1F
list(, $first_two_bytes) = unpack('n', $gz_data);

if (0x08 === $first_nibble && 0 === ($first_two_bytes % 0x1F)) {
if ($first_nibble === 0x08 && ($first_two_bytes % 0x1F) === 0) {
$huffman_encoded = true;
}

if ($huffman_encoded) {
$decompressed = @gzinflate(substr($gz_data, 2));
if (false !== $decompressed) {
if ($decompressed !== false) {
return $decompressed;
}
}

if ("\x50\x4b\x03\x04" === substr($gz_data, 0, 4)) {
if (substr($gz_data, 0, 4) === "\x50\x4b\x03\x04") {
// ZIP file format header
// Offset 6: 2 bytes, General-purpose field
// Offset 26: 2 bytes, filename length
Expand All @@ -942,7 +942,7 @@ public static function compatible_gzinflate($gz_data) {
// If the file has been compressed on the fly, 0x08 bit is set of
// the general purpose field. We can use this to differentiate
// between a compressed document, and a ZIP file
$zip_compressed_on_the_fly = (0x08 === (0x08 & $general_purpose_flag));
$zip_compressed_on_the_fly = ((0x08 & $general_purpose_flag) === 0x08);

if (!$zip_compressed_on_the_fly) {
// Don't attempt to decode a compressed zip file
Expand All @@ -953,22 +953,22 @@ public static function compatible_gzinflate($gz_data) {
// offsets:
$first_file_start = array_sum(unpack('v2', substr($gz_data, 26, 4)));
$decompressed = @gzinflate(substr($gz_data, 30 + $first_file_start));
if (false !== $decompressed) {
if ($decompressed !== false) {
return $decompressed;
}
return false;
}

// Finally fall back to straight gzinflate
$decompressed = @gzinflate($gz_data);
if (false !== $decompressed) {
if ($decompressed !== false) {
return $decompressed;
}

// Fallback for all above failing, not expected, but included for
// debugging and preventing regressions and to track stats
$decompressed = @gzinflate(substr($gz_data, 2));
if (false !== $decompressed) {
if ($decompressed !== false) {
return $decompressed;
}

Expand Down
4 changes: 2 additions & 2 deletions library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function request_multiple($requests, $options) {
// Parse the finished requests before we start getting the new ones
foreach ($to_process as $key => $done) {
$options = $requests[$key]['options'];
if (CURLE_OK !== $done['result']) {
if ($done['result'] !== CURLE_OK) {
//get error string for handle.
$reason = curl_error($done['handle']);
$exception = new Requests_Exception_Transport_cURL(
Expand Down Expand Up @@ -386,7 +386,7 @@ protected function setup_handle($url, $headers, $data, $options) {
curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
}

if (true === $options['blocking']) {
if ($options['blocking'] === true) {
curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array($this, 'stream_headers'));
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array($this, 'stream_body'));
curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion library/Requests/Transport/fsockopen.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function request($url, $headers = array(), $data = array(), $options = ar
if (!isset($case_insensitive_headers['Host'])) {
$out .= sprintf('Host: %s', $url_parts['host']);

if (('http' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 80) || ('https' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 443)) {
if ((strtolower($url_parts['scheme']) === 'http' && $url_parts['port'] !== 80) || (strtolower($url_parts['scheme']) === 'https' && $url_parts['port'] !== 443)) {
$out .= ':' . $url_parts['port'];
}
$out .= "\r\n";
Expand Down
4 changes: 2 additions & 2 deletions tests/Transport/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function setExpectedException($exception, $message = '', $code = null) {
}
else {
$this->expectException($exception);
if (null !== $message) {
if ($message !== null) {
$this->expectExceptionMessage($message);
}
if (null !== $code) {
if ($code !== null) {
$this->expectExceptionCode($code);
}
}
Expand Down