fixes from scrutinizer-ci

This commit is contained in:
Ahmad Nassri
2014-12-18 00:05:49 -05:00
parent ed76b17884
commit 97f51e1269
3 changed files with 36 additions and 33 deletions

View File

@@ -241,7 +241,7 @@ class Request
private static function getArrayFromQuerystring($query) private static function getArrayFromQuerystring($query)
{ {
$query = preg_replace_callback('/(?:^|(?<=&))[^=[]+/', function($match) { $query = preg_replace_callback('/(?:^|(?<=&))[^=[]+/', function ($match) {
return bin2hex(urldecode($match[0])); return bin2hex(urldecode($match[0]));
}, $query); }, $query);

View File

@@ -18,7 +18,7 @@ class Response
public function __construct($code, $raw_body, $headers) public function __construct($code, $raw_body, $headers)
{ {
$this->code = $code; $this->code = $code;
$this->headers = http_parse_headers($headers); $this->headers = $this->parseHeaders($headers);
$this->raw_body = $raw_body; $this->raw_body = $raw_body;
$this->body = $raw_body; $this->body = $raw_body;
$json = json_decode($raw_body); $json = json_decode($raw_body);
@@ -27,20 +27,22 @@ class Response
$this->body = $json; $this->body = $json;
} }
} }
}
/** /**
* if PECL_HTTP is not available use a fall back function * if PECL_HTTP is not available use a fall back function
* *
* thanks to ricardovermeltfoort@gmail.com * thanks to ricardovermeltfoort@gmail.com
* http://php.net/manual/en/function.http-parse-headers.php#112986 * http://php.net/manual/en/function.http-parse-headers.php#112986
*/ */
if (!function_exists('http_parse_headers')) { private function parseHeaders($raw_headers) {
function http_parse_headers($raw_headers) { if (function_exists('http_parse_headers')) {
return http_parse_headers($raw_headers);
} else {
$headers = array(); $headers = array();
$key = ''; $key = '';
foreach(explode("\n", $raw_headers) as $i => $h) { foreach (explode("\n", $raw_headers) as $i => $h) {
$h = explode(':', $h, 2); $h = explode(':', $h, 2);
if (isset($h[1])) { if (isset($h[1])) {
@@ -56,7 +58,7 @@ if (!function_exists('http_parse_headers')) {
} else { } else {
if (substr($h[0], 0, 1) == "\t") { if (substr($h[0], 0, 1) == "\t") {
$headers[$key] .= "\r\n\t".trim($h[0]); $headers[$key] .= "\r\n\t".trim($h[0]);
} elseif (!$key){ } elseif (!$key) {
$headers[0] = trim($h[0]); $headers[0] = trim($h[0]);
} }
} }
@@ -64,4 +66,5 @@ if (!function_exists('http_parse_headers')) {
return $headers; return $headers;
} }
}
} }

View File

@@ -303,7 +303,7 @@ class UnirestTest extends \PHPUnit_Framework_TestCase
{ {
Request::timeout(1); Request::timeout(1);
$response = Request::get('http://httpbin.org/delay/3'); Request::get('http://httpbin.org/delay/3');
Request::timeout(null); // Cleaning timeout for the other tests Request::timeout(null); // Cleaning timeout for the other tests
} }
@@ -353,7 +353,7 @@ class UnirestTest extends \PHPUnit_Framework_TestCase
public function testBasicAuthentication() public function testBasicAuthentication()
{ {
$response = Request::get('http://httpbin.org/get', null, null, 'user', 'password'); $response = Request::get('http://httpbin.org/get', null, array(), 'user', 'password');
$headers = $response->body->headers; $headers = $response->body->headers;
$this->assertEquals('Basic dXNlcjpwYXNzd29yZA==', $headers->Authorization); $this->assertEquals('Basic dXNlcjpwYXNzd29yZA==', $headers->Authorization);
} }