From 04a9a4924549f1a4085af3dcdb0562b1ac12ff3b Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 28 Apr 2017 12:35:59 -0700 Subject: [PATCH] return code as int --- src/p3k/HTTP.php | 4 ++-- src/p3k/HTTP/Curl.php | 12 ++++++------ src/p3k/HTTP/Stream.php | 6 +++--- src/p3k/HTTP/Test.php | 16 ++++++++-------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/p3k/HTTP.php b/src/p3k/HTTP.php index b475f1d..26443d4 100644 --- a/src/p3k/HTTP.php +++ b/src/p3k/HTTP.php @@ -78,7 +78,7 @@ class HTTP { } private static function _parse_headers($headers) { - $retVal = array(); + $retVal = []; $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $headers)); foreach($fields as $field) { if(preg_match('/([^:]+): (.+)/m', $field, $match)) { @@ -91,7 +91,7 @@ class HTTP { }, strtolower(trim($match[1]))); if(isset($retVal[$match[1]])) { if(!is_array($retVal[$match[1]])) - $retVal[$match[1]] = array($retVal[$match[1]]); + $retVal[$match[1]] = [$retVal[$match[1]]]; $retVal[$match[1]][] = $match[2]; } else { $retVal[$match[1]] = trim($match[2]); diff --git a/src/p3k/HTTP/Curl.php b/src/p3k/HTTP/Curl.php index 7c0e4bb..ef081e2 100644 --- a/src/p3k/HTTP/Curl.php +++ b/src/p3k/HTTP/Curl.php @@ -22,7 +22,7 @@ class Curl implements Transport { $response = curl_exec($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header_str = trim(substr($response, 0, $header_size)); - return array( + return [ 'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE), 'header' => $header_str, 'body' => substr($response, $header_size), @@ -30,7 +30,7 @@ class Curl implements Transport { 'error_description' => curl_error($ch), 'url' => curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), 'debug' => $response - ); + ]; } public function post($url, $body, $headers=[]) { @@ -43,7 +43,7 @@ class Curl implements Transport { $response = curl_exec($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header_str = trim(substr($response, 0, $header_size)); - return array( + return [ 'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE), 'header' => $header_str, 'body' => substr($response, $header_size), @@ -51,7 +51,7 @@ class Curl implements Transport { 'error_description' => curl_error($ch), 'url' => curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), 'debug' => $response - ); + ]; } public function head($url, $headers=[]) { @@ -61,14 +61,14 @@ class Curl implements Transport { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_NOBODY, true); $response = curl_exec($ch); - return array( + return [ 'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE), 'header' => trim($response), 'error' => self::error_string_from_code(curl_errno($ch)), 'error_description' => curl_error($ch), 'url' => curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), 'debug' => $response - ); + ]; } private function _set_curlopts($ch, $url) { diff --git a/src/p3k/HTTP/Stream.php b/src/p3k/HTTP/Stream.php index fb3c4fa..70d070f 100644 --- a/src/p3k/HTTP/Stream.php +++ b/src/p3k/HTTP/Stream.php @@ -72,14 +72,14 @@ class Stream implements Transport { ]; } - return array( + return [ 'code' => self::parse_response_code($http_response_header), 'header' => implode("\r\n", $http_response_header), 'body' => $body, 'error' => $error ? $error['code'] : false, 'error_description' => $error ? $error['description'] : false, 'url' => $url, - ); + ]; } private function _stream_context($method, $url, $body=false, $headers=[]) { @@ -115,7 +115,7 @@ class Stream implements Transport { $code = $match[1]; } } - return $code; + return (int)$code; } } diff --git a/src/p3k/HTTP/Test.php b/src/p3k/HTTP/Test.php index ab05a9b..37219ef 100644 --- a/src/p3k/HTTP/Test.php +++ b/src/p3k/HTTP/Test.php @@ -43,14 +43,14 @@ class Test implements Transport { public function head($url, $headers=[]) { $response = $this->_read_file($url); - return array( - 'code' => $response['code'], + return [ + 'code' => (int)$response['code'], 'headers' => $response['headers'], 'rels' => $response['rels'], 'error' => '', 'error_description' => '', 'url' => $response['url'] - ); + ]; } private function _read_file($url) { @@ -100,19 +100,19 @@ class Test implements Transport { $effectiveUrl = $url; } - return array( - 'code' => $code, + return [ + 'code' => (int)$code, 'headers' => $parsedHeaders, 'rels' => \IndieWeb\http_rels($headers), 'body' => $body, 'error' => (isset($parsedHeaders['X-Test-Error']) ? $parsedHeaders['X-Test-Error'] : ''), 'error_description' => '', 'url' => $effectiveUrl - ); + ]; } private static function _parse_headers($headers) { - $retVal = array(); + $retVal = []; $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $headers)); foreach($fields as $field) { if(preg_match('/([^:]+): (.+)/m', $field, $match)) { @@ -125,7 +125,7 @@ class Test implements Transport { }, strtolower(trim($match[1]))); if(isset($retVal[$match[1]])) { if(!is_array($retVal[$match[1]])) - $retVal[$match[1]] = array($retVal[$match[1]]); + $retVal[$match[1]] = [$retVal[$match[1]]]; $retVal[$match[1]][] = $match[2]; } else { $retVal[$match[1]] = trim($match[2]);