Skip to content

Commit e727593

Browse files
committed
Merge pull request php-curl-class#72 from Yahasana/patch-1
Add minor performance enhancements
2 parents 745b1c6 + 209b35a commit e727593

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/Curl/Curl.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function setCookieJar($cookie_jar)
219219

220220
public function setOpt($option, $value, $_ch = null)
221221
{
222-
$ch = is_null($_ch) ? $this->curl : $_ch;
222+
$ch = $_ch === null ? $this->curl : $_ch;
223223

224224
$required_options = array(
225225
CURLINFO_HEADER_OUT => 'CURLINFO_HEADER_OUT',
@@ -330,15 +330,12 @@ private function parseResponse($response)
330330
$raw_response = $response;
331331

332332
if (isset($response_headers['Content-Type'])) {
333-
if (preg_match('/^application\/json/i', $response_headers['Content-Type'])) {
333+
if (stripos($response_headers['Content-Type'], 'application/json') === 0) {
334334
$json_obj = json_decode($response, false);
335-
if (!is_null($json_obj)) {
335+
if ($json_obj !== null) {
336336
$response = $json_obj;
337337
}
338-
} elseif (preg_match('/^application\/atom\+xml/i', $response_headers['Content-Type']) ||
339-
preg_match('/^application\/rss\+xml/i', $response_headers['Content-Type']) ||
340-
preg_match('/^application\/xml/i', $response_headers['Content-Type']) ||
341-
preg_match('/^text\/xml/i', $response_headers['Content-Type'])) {
338+
} elseif (preg_match('~^(?:text/|application/(?:atom\+|rss\+)?)xml~i', $response_headers['Content-Type'])) {
342339
$xml_obj = @simplexml_load_string($response);
343340
if (!($xml_obj === false)) {
344341
$response = $xml_obj;
@@ -398,7 +395,7 @@ private function postfields($data)
398395

399396
protected function exec($_ch = null)
400397
{
401-
$ch = is_null($_ch) ? $this : $_ch;
398+
$ch = $_ch === null ? $this : $_ch;
402399

403400
if ($ch->multi_child) {
404401
$ch->raw_response = curl_multi_getcontent($ch->curl);
@@ -461,7 +458,7 @@ public static function is_array_multidim($array)
461458
return false;
462459
}
463460

464-
return !(count($array) === count($array, COUNT_RECURSIVE));
461+
return (bool)count(array_filter($array, 'is_array'));
465462
}
466463

467464
public static function http_build_multi_query($data, $key = null)
@@ -477,9 +474,9 @@ public static function http_build_multi_query($data, $key = null)
477474
foreach ($data as $k => $value) {
478475
if (is_string($value) || is_numeric($value)) {
479476
$brackets = $is_array_assoc ? '[' . $k . ']' : '[]';
480-
$query[] = urlencode(is_null($key) ? $k : $key . $brackets) . '=' . rawurlencode($value);
477+
$query[] = urlencode($key === null ? $k : $key . $brackets) . '=' . rawurlencode($value);
481478
} elseif (is_array($value)) {
482-
$nested = is_null($key) ? $k : $key . '[' . $k . ']';
479+
$nested = $key === null ? $k : $key . '[' . $k . ']';
483480
$query[] = self::http_build_multi_query($value, $nested);
484481
}
485482
}
@@ -494,7 +491,7 @@ class CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
494491

495492
public function offsetSet($offset, $value)
496493
{
497-
if (is_null($offset)) {
494+
if ($offset === null) {
498495
$this->container[] = $value;
499496
} else {
500497
$index = array_search(strtolower($offset), array_keys(array_change_key_case($this->container, CASE_LOWER)));

0 commit comments

Comments
 (0)