From 7636620338e32ea4d0beef9e4fe2653b5719448f Mon Sep 17 00:00:00 2001 From: sosherof Date: Thu, 11 May 2023 15:39:09 -0700 Subject: [PATCH 1/3] Updates applied per suggestion of Rector to be 7.2 to 8.2 compatible. --- downloads/httpful.phar | Bin 0 -> 69013 bytes src/Httpful/Bootstrap.php | 14 ++-- src/Httpful/Handlers/CsvHandler.php | 6 +- src/Httpful/Handlers/FormHandler.php | 4 +- src/Httpful/Handlers/JsonHandler.php | 2 +- src/Httpful/Handlers/MimeHandlerAdapter.php | 10 +-- src/Httpful/Handlers/XmlHandler.php | 22 +++--- src/Httpful/Http.php | 36 ++++----- src/Httpful/Httpful.php | 6 +- src/Httpful/Mime.php | 30 ++++---- src/Httpful/Proxy.php | 6 +- src/Httpful/Request.php | 78 ++++++++++---------- src/Httpful/Response.php | 28 +++---- src/Httpful/Response/Headers.php | 9 +-- tests/Httpful/HttpfulTest.php | 58 +++++++-------- tests/bootstrap-server.php | 4 +- 16 files changed, 158 insertions(+), 155 deletions(-) create mode 100644 downloads/httpful.phar diff --git a/downloads/httpful.phar b/downloads/httpful.phar new file mode 100644 index 0000000000000000000000000000000000000000..9a7ce6cde1de58c83944bc34e1d90cf635c24ee8 GIT binary patch literal 69013 zcmd_TTWp+JwjS2UjuTHKoy15S1V)1MHxDsYq0%XKRg}b0kAWb541yR2^5Wni2#^EVFM)x;K#%}_@I!#WPd0)80TLrX9`cf> z7`Y-yzHeRj-v6ywl)C5GNzJs1_5b^__S$Q&y>5H$Pd+_AJ%8`r44>82Z0EE)%JwD~ z2ib#OKi9{6wzhWGJ?9_o*6Cz&etgkiImfTo!q2r#Z*bVZILg~CK3!W~O$)6))EcXw z4TqEQWYj%J-SbfOxxIcKUazgOm90T<(q{YGL#Oj_{n37BWBc*W)}zf`yvaVj``){M z|Ifbj&R=*(|NFgn{(1bBc8#C!{6+j%3&HQd`_4PP`LB=o{pJ7mxBk<=^Ls4*&O0mk z&ns-cI?T@}z2RVWV>lS(hx~JMG#Z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;^v2byKqFF0 zGPojv9wt3RKj?iT^riCVg(4sYzi@y?5EODoRAngxsop)?&CQWng2p=I7LZzYlU-JL<=j4A(-SDF3tgR7&(COR-^^O zl`P)fH@mtq`^^H@@NH?hE5S7n5k}VsrPR6ZF$;D`jJ@f+gb-P4>w^X$=Ku$!C0Ryu z4o`$!f@nAxU)XVCK@Bj~giE7=OO`W8mSx{D%W%o#-&RaeAX07?I+=;*4=E<)AHS*o*GF7^jFRd z3FsojRY9p!uIK5$mORVw9S6A&w?a!;r|+Sp3X-svjxpx3HjWyF+G#D)FV2!Bre4_b zLP}IalVpTuTZP1-?9h~cX=DM$=GzR~L3*st05MKTaUj;X$@tl=nxLF|Lq-e{*I5p< zC8CRvTR|huju_cC%+9)fN{HC03-FP72*Y+H59Ss6TP>Y<_?MNdRjQsVZM^ zd)z6Hg@l~I7S=fd1^(%9pr-&Z$uW~TIe(5jQ#O+6KynYgui&&R(!Qmgizq@vZdU;J z+}hh-{`ljMezpv$U=EIie(zA!pj9+Ws?rM@3LO-h!ftFahjx7tI(@qTVEN)Hy#?^Ta5L)m>e&EoGyU!+;5GM zAB9F7k$gVQ@H?1kD7&~SXTxx+tpkR~$fpvnN@epHkVZVF{9BSkS6fZVmZ&uBG~1sX zTi%Im0-jO(#o%ZqMMh1FVek?0wN0HPtT}C}j92h97boq~iC1TR@pGn&fdE+&Q+U9~ zINW&y#S;0dDlSEymvW9|b(7krPScGmrb+1`a2RYIZbmF{nH%IX)fubvv1+NLAq;{_ ztAr;$fCGs?T+&R6rL%8aVZd{`)439>!ig>2CRbReGa2rw4; new \Httpful\Handlers\JsonHandler(), \Httpful\Mime::XML => new \Httpful\Handlers\XmlHandler(), \Httpful\Mime::FORM => new \Httpful\Handlers\FormHandler(), \Httpful\Mime::CSV => new \Httpful\Handlers\CsvHandler(), - ); + ]; foreach ($handlers as $mime => $handler) { // Don't overwrite if the handler has already been registered diff --git a/src/Httpful/Handlers/CsvHandler.php b/src/Httpful/Handlers/CsvHandler.php index de7b15b..69c79d0 100644 --- a/src/Httpful/Handlers/CsvHandler.php +++ b/src/Httpful/Handlers/CsvHandler.php @@ -18,13 +18,13 @@ public function parse($body) if (empty($body)) return null; - $parsed = array(); + $parsed = []; $fp = fopen('data://text/plain;base64,' . base64_encode($body), 'r'); while (($r = fgetcsv($fp)) !== FALSE) { $parsed[] = $r; } - if (empty($parsed)) + if ($parsed === []) throw new \Exception("Unable to parse response as CSV"); return $parsed; } @@ -33,7 +33,7 @@ public function parse($body) * @param mixed $payload * @return string */ - public function serialize($payload) + public function serialize($payload): string { $fp = fopen('php://temp/maxmemory:'. (6*1024*1024), 'r+'); $i = 0; diff --git a/src/Httpful/Handlers/FormHandler.php b/src/Httpful/Handlers/FormHandler.php index fea1c37..0ff05a8 100644 --- a/src/Httpful/Handlers/FormHandler.php +++ b/src/Httpful/Handlers/FormHandler.php @@ -14,7 +14,7 @@ class FormHandler extends MimeHandlerAdapter */ public function parse($body) { - $parsed = array(); + $parsed = []; parse_str($body, $parsed); return $parsed; } @@ -23,7 +23,7 @@ public function parse($body) * @param mixed $payload * @return string */ - public function serialize($payload) + public function serialize($payload): string { return http_build_query($payload, null, '&'); } diff --git a/src/Httpful/Handlers/JsonHandler.php b/src/Httpful/Handlers/JsonHandler.php index 6166283..6565f60 100644 --- a/src/Httpful/Handlers/JsonHandler.php +++ b/src/Httpful/Handlers/JsonHandler.php @@ -14,7 +14,7 @@ class JsonHandler extends MimeHandlerAdapter public function init(array $args) { - $this->decode_as_array = !!(array_key_exists('decode_as_array', $args) ? $args['decode_as_array'] : false); + $this->decode_as_array = (bool) ($args['decode_as_array'] ?? false); } /** diff --git a/src/Httpful/Handlers/MimeHandlerAdapter.php b/src/Httpful/Handlers/MimeHandlerAdapter.php index e57ebb0..53e04ad 100644 --- a/src/Httpful/Handlers/MimeHandlerAdapter.php +++ b/src/Httpful/Handlers/MimeHandlerAdapter.php @@ -10,7 +10,7 @@ class MimeHandlerAdapter { - public function __construct(array $args = array()) + public function __construct(array $args = []) { $this->init($args); } @@ -36,18 +36,18 @@ public function parse($body) * @param mixed $payload * @return string */ - function serialize($payload) + function serialize($payload): string { return (string) $payload; } - protected function stripBom($body) + protected function stripBom($body): string { if ( substr($body,0,3) === "\xef\xbb\xbf" ) // UTF-8 $body = substr($body,3); - else if ( substr($body,0,4) === "\xff\xfe\x00\x00" || substr($body,0,4) === "\x00\x00\xfe\xff" ) // UTF-32 + elseif ( substr($body,0,4) === "\xff\xfe\x00\x00" || substr($body,0,4) === "\x00\x00\xfe\xff" ) // UTF-32 $body = substr($body,4); - else if ( substr($body,0,2) === "\xff\xfe" || substr($body,0,2) === "\xfe\xff" ) // UTF-16 + elseif ( substr($body,0,2) === "\xff\xfe" || substr($body,0,2) === "\xfe\xff" ) // UTF-16 $body = substr($body,2); return $body; } diff --git a/src/Httpful/Handlers/XmlHandler.php b/src/Httpful/Handlers/XmlHandler.php index 9298a1f..938bebb 100644 --- a/src/Httpful/Handlers/XmlHandler.php +++ b/src/Httpful/Handlers/XmlHandler.php @@ -23,10 +23,10 @@ class XmlHandler extends MimeHandlerAdapter /** * @param array $conf sets configuration options */ - public function __construct(array $conf = array()) + public function __construct(array $conf = []) { - $this->namespace = isset($conf['namespace']) ? $conf['namespace'] : ''; - $this->libxml_opts = isset($conf['libxml_opts']) ? $conf['libxml_opts'] : 0; + $this->namespace = $conf['namespace'] ?? ''; + $this->libxml_opts = $conf['libxml_opts'] ?? 0; } /** @@ -50,9 +50,9 @@ public function parse($body) * @return string * @throws \Exception if unable to serialize */ - public function serialize($payload) + public function serialize($payload): string { - list($_, $dom) = $this->_future_serializeAsXml($payload); + [$_, $dom] = $this->_future_serializeAsXml($payload); return $dom->saveXml(); } @@ -75,7 +75,7 @@ public function serialize_clean($payload) * @param mixed $node to serialize * @author Ted Zellers */ - public function serialize_node(&$xmlw, $node){ + public function serialize_node(&$xmlw, $node) { if (!is_array($node)){ $xmlw->text($node); } else { @@ -107,16 +107,16 @@ private function _future_serializeAsXml($value, $node = null, $dom = null) $objNode = $dom->createElement(get_class($value)); $node->appendChild($objNode); $this->_future_serializeObjectAsXml($value, $objNode, $dom); - } else if (is_array($value)) { + } elseif (is_array($value)) { $arrNode = $dom->createElement('array'); $node->appendChild($arrNode); $this->_future_serializeArrayAsXml($value, $arrNode, $dom); - } else if (is_bool($value)) { + } elseif (is_bool($value)) { $node->appendChild($dom->createTextNode($value?'TRUE':'FALSE')); } else { $node->appendChild($dom->createTextNode($value)); } - return array($node, $dom); + return [$node, $dom]; } /** * @author Zack Douglas @@ -132,7 +132,7 @@ private function _future_serializeArrayAsXml($value, &$parent, &$dom) $parent->appendChild($el); $this->_future_serializeAsXml($v, $el, $dom); } - return array($parent, $dom); + return [$parent, $dom]; } /** * @author Zack Douglas @@ -147,6 +147,6 @@ private function _future_serializeObjectAsXml($value, &$parent, &$dom) $this->_future_serializeAsXml($pr->getValue($value), $el, $dom); } } - return array($parent, $dom); + return [$parent, $dom]; } } \ No newline at end of file diff --git a/src/Httpful/Http.php b/src/Httpful/Http.php index 1c9aa0d..c56ab93 100644 --- a/src/Httpful/Http.php +++ b/src/Httpful/Http.php @@ -7,28 +7,28 @@ */ class Http { - const HEAD = 'HEAD'; - const GET = 'GET'; - const POST = 'POST'; - const PUT = 'PUT'; - const DELETE = 'DELETE'; - const PATCH = 'PATCH'; - const OPTIONS = 'OPTIONS'; - const TRACE = 'TRACE'; + public const HEAD = 'HEAD'; + public const GET = 'GET'; + public const POST = 'POST'; + public const PUT = 'PUT'; + public const DELETE = 'DELETE'; + public const PATCH = 'PATCH'; + public const OPTIONS = 'OPTIONS'; + public const TRACE = 'TRACE'; /** * @return array of HTTP method strings */ - public static function safeMethods() + public static function safeMethods(): array { - return array(self::HEAD, self::GET, self::OPTIONS, self::TRACE); + return [self::HEAD, self::GET, self::OPTIONS, self::TRACE]; } /** * @param string HTTP method * @return bool */ - public static function isSafeMethod($method) + public static function isSafeMethod($method): bool { return in_array($method, self::safeMethods()); } @@ -37,7 +37,7 @@ public static function isSafeMethod($method) * @param string HTTP method * @return bool */ - public static function isUnsafeMethod($method) + public static function isUnsafeMethod($method): bool { return !in_array($method, self::safeMethods()); } @@ -45,19 +45,19 @@ public static function isUnsafeMethod($method) /** * @return array list of (always) idempotent HTTP methods */ - public static function idempotentMethods() + public static function idempotentMethods(): array { // Though it is possible to be idempotent, POST // is not guarunteed to be, and more often than // not, it is not. - return array(self::HEAD, self::GET, self::PUT, self::DELETE, self::OPTIONS, self::TRACE, self::PATCH); + return [self::HEAD, self::GET, self::PUT, self::DELETE, self::OPTIONS, self::TRACE, self::PATCH]; } /** * @param string HTTP method * @return bool */ - public static function isIdempotent($method) + public static function isIdempotent($method): bool { return in_array($method, self::safeidempotentMethodsMethods()); } @@ -66,7 +66,7 @@ public static function isIdempotent($method) * @param string HTTP method * @return bool */ - public static function isNotIdempotent($method) + public static function isNotIdempotent($method): bool { return !in_array($method, self::idempotentMethods()); } @@ -78,9 +78,9 @@ public static function isNotIdempotent($method) * * @return array of HTTP method strings */ - public static function canHaveBody() + public static function canHaveBody(): array { - return array(self::POST, self::PUT, self::PATCH, self::OPTIONS); + return [self::POST, self::PUT, self::PATCH, self::OPTIONS]; } } \ No newline at end of file diff --git a/src/Httpful/Httpful.php b/src/Httpful/Httpful.php index e235fa3..98d49b7 100644 --- a/src/Httpful/Httpful.php +++ b/src/Httpful/Httpful.php @@ -3,9 +3,9 @@ namespace Httpful; class Httpful { - const VERSION = '0.3.0'; + public const VERSION = '0.3.0'; - private static $mimeRegistrar = array(); + private static $mimeRegistrar = []; private static $default = null; /** @@ -40,7 +40,7 @@ public static function get($mimeType = null) * @param string $mimeType * @return bool */ - public static function hasParserRegistered($mimeType) + public static function hasParserRegistered($mimeType): bool { return isset(self::$mimeRegistrar[$mimeType]); } diff --git a/src/Httpful/Mime.php b/src/Httpful/Mime.php index 930b6e3..3965075 100644 --- a/src/Httpful/Mime.php +++ b/src/Httpful/Mime.php @@ -8,35 +8,35 @@ */ class Mime { - const JSON = 'application/json'; - const XML = 'application/xml'; - const XHTML = 'application/html+xml'; - const FORM = 'application/x-www-form-urlencoded'; - const UPLOAD = 'multipart/form-data'; - const PLAIN = 'text/plain'; - const JS = 'text/javascript'; - const HTML = 'text/html'; - const YAML = 'application/x-yaml'; - const CSV = 'text/csv'; + public const JSON = 'application/json'; + public const XML = 'application/xml'; + public const XHTML = 'application/html+xml'; + public const FORM = 'application/x-www-form-urlencoded'; + public const UPLOAD = 'multipart/form-data'; + public const PLAIN = 'text/plain'; + public const JS = 'text/javascript'; + public const HTML = 'text/html'; + public const YAML = 'application/x-yaml'; + public const CSV = 'text/csv'; /** * Map short name for a mime type * to a full proper mime type */ - public static $mimes = array( + public static $mimes = [ 'json' => self::JSON, 'xml' => self::XML, 'form' => self::FORM, 'plain' => self::PLAIN, 'text' => self::PLAIN, - 'upload' => self::UPLOAD, + 'upload' => self::UPLOAD, 'html' => self::HTML, 'xhtml' => self::XHTML, 'js' => self::JS, 'javascript'=> self::JS, 'yaml' => self::YAML, 'csv' => self::CSV, - ); + ]; /** * Get the full Mime Type name from a "short name". @@ -44,7 +44,7 @@ class Mime * @param string $short_name common name for mime type (e.g. json) * @return string full mime type (e.g. application/json) */ - public static function getFullMime($short_name) + public static function getFullMime($short_name): bool { return array_key_exists($short_name, self::$mimes) ? self::$mimes[$short_name] : $short_name; } @@ -53,7 +53,7 @@ public static function getFullMime($short_name) * @param string $short_name * @return bool */ - public static function supportsMimeType($short_name) + public static function supportsMimeType($short_name): bool { return array_key_exists($short_name, self::$mimes); } diff --git a/src/Httpful/Proxy.php b/src/Httpful/Proxy.php index 4ab9ea6..611f017 100644 --- a/src/Httpful/Proxy.php +++ b/src/Httpful/Proxy.php @@ -10,7 +10,7 @@ */ class Proxy { - const HTTP = CURLPROXY_HTTP; - const SOCKS4 = CURLPROXY_SOCKS4; - const SOCKS5 = CURLPROXY_SOCKS5; + public const HTTP = CURLPROXY_HTTP; + public const SOCKS4 = CURLPROXY_SOCKS4; + public const SOCKS5 = CURLPROXY_SOCKS5; } diff --git a/src/Httpful/Request.php b/src/Httpful/Request.php index c04d230..5e9aae8 100644 --- a/src/Httpful/Request.php +++ b/src/Httpful/Request.php @@ -47,20 +47,20 @@ class Request { // Option constants - const SERIALIZE_PAYLOAD_NEVER = 0; - const SERIALIZE_PAYLOAD_ALWAYS = 1; - const SERIALIZE_PAYLOAD_SMART = 2; + public const SERIALIZE_PAYLOAD_NEVER = 0; + public const SERIALIZE_PAYLOAD_ALWAYS = 1; + public const SERIALIZE_PAYLOAD_SMART = 2; - const MAX_REDIRECTS_DEFAULT = 25; + public const MAX_REDIRECTS_DEFAULT = 25; public $uri, $method = Http::GET, - $headers = array(), + $headers = [], $raw_headers = '', $strict_ssl = false, $content_type, $expected_type, - $additional_curl_opts = array(), + $additional_curl_opts = [], $auto_parse = true, $serialize_payload_method = self::SERIALIZE_PAYLOAD_SMART, $username, @@ -72,7 +72,12 @@ class Request $send_callback, $follow_redirects = false, $max_redirects = self::MAX_REDIRECTS_DEFAULT, - $payload_serializers = array(); + $payload_serializers = [], + $timeout = null, + $client_cert = null, + $client_key = null, + $client_passphrase = null, + $client_encoding = null; // Options // private $_options = array( @@ -98,7 +103,8 @@ protected function __construct($attrs = null) { if (!is_array($attrs)) return; foreach ($attrs as $attr => $value) { - $this->$attr = $value; + if (property_exists($this, $attr)) + $this->$attr = $value; } } @@ -146,33 +152,33 @@ public static function d($attr) /** * @return bool does the request have a timeout? */ - public function hasTimeout() + public function hasTimeout(): bool { - return isset($this->timeout); + return $this->timeout !== null; } /** * @return bool has the internal curl request been initialized? */ - public function hasBeenInitialized() + public function hasBeenInitialized(): bool { - return isset($this->_ch); + return $this->_ch !== null; } /** * @return bool Is this request setup for basic auth? */ - public function hasBasicAuth() + public function hasBasicAuth(): bool { - return isset($this->password) && isset($this->username); + return $this->password !== null && $this->username !== null; } /** * @return bool Is this request setup for digest auth? */ - public function hasDigestAuth() + public function hasDigestAuth(): bool { - return isset($this->password) && isset($this->username) && $this->additional_curl_opts[CURLOPT_HTTPAUTH] == CURLAUTH_DIGEST; + return $this->password !== null && $this->username !== null && $this->additional_curl_opts[CURLOPT_HTTPAUTH] == CURLAUTH_DIGEST; } /** @@ -307,9 +313,9 @@ public function authenticateWithDigest($username, $password) /** * @return bool is this request setup for client side cert? */ - public function hasClientSideCert() + public function hasClientSideCert(): bool { - return isset($this->client_cert) && isset($this->client_key); + return $this->client_cert !== null && $this->client_key !==null; } /** @@ -481,7 +487,7 @@ public function useProxy($proxy_host, $proxy_port = 80, $auth_type = null, $auth { $this->addOnCurlOption(CURLOPT_PROXY, "{$proxy_host}:{$proxy_port}"); $this->addOnCurlOption(CURLOPT_PROXYTYPE, $proxy_type); - if (in_array($auth_type, array(CURLAUTH_BASIC,CURLAUTH_NTLM))) { + if (in_array($auth_type, [CURLAUTH_BASIC,CURLAUTH_NTLM])) { $this->addOnCurlOption(CURLOPT_PROXYAUTH, $auth_type) ->addOnCurlOption(CURLOPT_PROXYUSERPWD, "{$auth_username}:{$auth_password}"); } @@ -511,7 +517,7 @@ public function useSocks5Proxy($proxy_host, $proxy_port = 80, $auth_type = null, /** * @return bool is this request setup for using proxy? */ - public function hasProxy() + public function hasProxy(): bool { /* We must be aware that proxy variables could come from environment also. In curl extension, http proxy can be specified not only via CURLOPT_PROXY option, @@ -756,7 +762,7 @@ public function __call($method, $args) // This method also adds the custom header support as described in the // method comments - if (count($args) === 0) + if ($args === []) return; // Strip the sugar. If it leads with "with", strip. @@ -791,7 +797,7 @@ private static function _initializeDefaults() // recusion. Do not use this syntax elsewhere. // It goes against the whole readability // and transparency idea. - self::$_template = new Request(array('method' => Http::GET)); + self::$_template = new Request(['method' => Http::GET]); // This is more like it... self::$_template @@ -818,7 +824,7 @@ private function _error($error) { // TODO add in support for various Loggers that follow // PSR 3 https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md - if (isset($this->error_callback)) { + if ($this->error_callback !== null) { $this->error_callback->__invoke($error); } else { error_log($error); @@ -860,14 +866,14 @@ public static function init($method = null, $mime = null) public function _curlPrep() { // Check for required stuff - if (!isset($this->uri)) + if ($this->uri === null) throw new \Exception('Attempting to send a request before defining a URI endpoint.'); - if (isset($this->payload)) { + if ($this->payload !== null) { $this->serialized_payload = $this->_serializePayload($this->payload); } - if (isset($this->send_callback)) { + if ($this->send_callback !== null) { call_user_func($this->send_callback, $this); } @@ -921,7 +927,7 @@ public function _curlPrep() // https://github.com/nategood/httpful/issues/84 // set Content-Length to the size of the payload if present - if (isset($this->payload)) { + if ($this->payload !== null) { curl_setopt($ch, CURLOPT_POSTFIELDS, $this->serialized_payload); if (!$this->isUpload()) { $this->headers['Content-Length'] = @@ -929,7 +935,7 @@ public function _curlPrep() } } - $headers = array(); + $headers = []; // https://github.com/nategood/httpful/issues/37 // Except header removes any HTTP 1.1 Continue from response headers $headers[] = 'Expect:'; @@ -941,7 +947,7 @@ public function _curlPrep() $headers[] = "Content-Type: {$this->content_type}"; // allow custom Accept header if set - if (!isset($this->headers['Accept'])) { + if ($this->headers['Accept'] === null) { // http://pretty-rfc.herokuapp.com/RFC2616#header.accept $accept = 'Accept: */*; q=0.5, text/plain; q=0.8, text/html;level=3;'; @@ -962,9 +968,9 @@ public function _curlPrep() } $url = \parse_url($this->uri); - $path = (isset($url['path']) ? $url['path'] : '/').(isset($url['query']) ? '?'.$url['query'] : ''); + $path = ($url['path'] ?? '/').(isset($url['query']) ? '?'.$url['query'] : ''); $this->raw_headers = "{$this->method} $path HTTP/1.1\r\n"; - $host = (isset($url['host']) ? $url['host'] : 'localhost').(isset($url['port']) ? ':'.$url['port'] : ''); + $host = ($url['host'] ?? 'localhost').(isset($url['port']) ? ':'.$url['port'] : ''); $this->raw_headers .= "Host: $host\r\n"; $this->raw_headers .= \implode("\r\n", $headers); $this->raw_headers .= "\r\n"; @@ -1004,7 +1010,7 @@ public function _determineLength($str) /** * @return bool */ - public function isUpload() + public function isUpload(): bool { return Mime::UPLOAD == $this->content_type; } @@ -1012,7 +1018,7 @@ public function isUpload() /** * @return string */ - public function buildUserAgent() + public function buildUserAgent(): string { $user_agent = 'User-Agent: Httpful/' . Httpful::VERSION . ' (cURL/'; $curl = \curl_version(); @@ -1042,9 +1048,7 @@ public function buildUserAgent() $user_agent .= " {$_SERVER['HTTP_USER_AGENT']}"; } - $user_agent .= ')'; - - return $user_agent; + return $user_agent . ')'; } /** @@ -1053,7 +1057,7 @@ public function buildUserAgent() */ public function buildResponse($result) { if ($result === false) { - if ($curlErrorNumber = curl_errno($this->_ch)) { + if (($curlErrorNumber = curl_errno($this->_ch)) !== 0) { $curlErrorString = curl_error($this->_ch); $this->_error($curlErrorString); diff --git a/src/Httpful/Response.php b/src/Httpful/Response.php index 09996b6..bdfd11a 100644 --- a/src/Httpful/Response.php +++ b/src/Httpful/Response.php @@ -18,7 +18,7 @@ class Response $code = 0, $content_type, $parent_type, - $charset, + $charset = null, $meta_data, $is_mime_vendor_specific = false, $is_mime_personal = false; @@ -31,7 +31,7 @@ class Response * @param Request $request * @param array $meta_data */ - public function __construct($body, $headers, Request $request, array $meta_data = array()) + public function __construct(string $body, string $headers, Request $request, array $meta_data = []) { $this->request = $request; $this->raw_headers = $headers; @@ -59,7 +59,7 @@ public function __construct($body, $headers, Request $request, array $meta_data * * @return bool Did we receive a 4xx or 5xx? */ - public function hasErrors() + public function hasErrors(): bool { return $this->code >= 400; } @@ -67,7 +67,7 @@ public function hasErrors() /** * @return bool */ - public function hasBody() + public function hasBody(): bool { return !empty($this->body); } @@ -77,7 +77,7 @@ public function hasBody() * (most often an associative array) based on the expected * Mime type. * @param string Http response body - * @return array|string|object the response parse accordingly + * @return mixed (array|string|object) the response parse accordingly */ public function _parse($body) { @@ -113,12 +113,12 @@ public function _parse($body) * @param string $headers raw headers * @return array parse headers */ - public function _parseHeaders($headers) + public function _parseHeaders(string $headers): array { return Response\Headers::fromString($headers)->toArray(); } - public function _parseCode($headers) + public function _parseCode(string $headers): int { $end = strpos($headers, "\r\n"); if ($end === false) $end = strlen($headers); @@ -126,7 +126,7 @@ public function _parseCode($headers) if (count($parts) < 2 || !is_numeric($parts[1])) { throw new \Exception("Unable to parse response code from HTTP response due to malformed response"); } - return intval($parts[1]); + return (int) $parts[1]; } /** @@ -136,12 +136,12 @@ public function _parseCode($headers) public function _interpretHeaders() { // Parse the Content-Type and charset - $content_type = isset($this->headers['Content-Type']) ? $this->headers['Content-Type'] : ''; + $content_type = $this->headers['Content-Type'] ?? ''; $content_type = explode(';', $content_type); $this->content_type = $content_type[0]; if (count($content_type) == 2 && strpos($content_type[1], '=') !== false) { - list($nill, $this->charset) = explode('=', $content_type[1]); + [$nill, $this->charset] = explode('=', $content_type[1]); } // RFC 2616 states "text/*" Content-Types should have a default @@ -149,13 +149,13 @@ public function _interpretHeaders() // are assumed to have UTF-8 unless otherwise specified. // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1 // http://www.w3.org/International/O-HTTP-charset.en.php - if (!isset($this->charset)) { + if ($this->charset === null ) { $this->charset = substr($this->content_type, 5) === 'text/' ? 'iso-8859-1' : 'utf-8'; } // Is vendor type? Is personal type? if (strpos($this->content_type, '/') !== false) { - list($type, $sub_type) = explode('/', $this->content_type); + [$type, $sub_type] = explode('/', $this->content_type); $this->is_mime_vendor_specific = substr($sub_type, 0, 4) === 'vnd.'; $this->is_mime_personal = substr($sub_type, 0, 4) === 'prs.'; } @@ -163,7 +163,7 @@ public function _interpretHeaders() // Parent type (e.g. xml for application/vnd.github.message+xml) $this->parent_type = $this->content_type; if (strpos($this->content_type, '+') !== false) { - list($vendor, $this->parent_type) = explode('+', $this->content_type, 2); + [$vendor, $this->parent_type] = explode('+', $this->content_type, 2); $this->parent_type = Mime::getFullMime($this->parent_type); } } @@ -171,7 +171,7 @@ public function _interpretHeaders() /** * @return string */ - public function __toString() + public function __toString(): string { return $this->raw_body; } diff --git a/src/Httpful/Response/Headers.php b/src/Httpful/Response/Headers.php index 8e8a8cd..63ea6d9 100644 --- a/src/Httpful/Response/Headers.php +++ b/src/Httpful/Response/Headers.php @@ -15,7 +15,7 @@ private function __construct($headers) } /** - * @param string $string + * @param string $string * @return Headers */ public static function fromString($string) @@ -23,7 +23,7 @@ public static function fromString($string) $headers = preg_split("/(\r|\n)+/", $string, -1, \PREG_SPLIT_NO_EMPTY); $parse_headers = array(); for ($i = 1; $i < count($headers); $i++) { - list($key, $raw_value) = explode(':', $headers[$i], 2); + [($key, $raw_value] = explode(':', $headers[$i], 2); $key = trim($key); $value = trim($raw_value); if (array_key_exists($key, $parse_headers)) { @@ -42,9 +42,8 @@ public static function fromString($string) /** * @param string $offset - * @return bool */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return $this->getCaseInsensitive($offset) !== null; } @@ -80,7 +79,7 @@ public function offsetUnset($offset) /** * @return int */ - public function count() + public function count(): int { return count($this->headers); } diff --git a/tests/Httpful/HttpfulTest.php b/tests/Httpful/HttpfulTest.php index 062973e..3b8787f 100644 --- a/tests/Httpful/HttpfulTest.php +++ b/tests/Httpful/HttpfulTest.php @@ -9,7 +9,7 @@ */ namespace Httpful\Test; -require(dirname(dirname(dirname(__FILE__))) . '/bootstrap.php'); +require(dirname(__FILE__),3) . '/bootstrap.php'); \Httpful\Bootstrap::init(); use Httpful\Httpful; @@ -23,16 +23,16 @@ class HttpfulTest extends \PHPUnit\Framework\TestCase { - const TEST_SERVER = TEST_SERVER; - const TEST_URL = 'http://127.0.0.1:8008'; - const TEST_URL_400 = 'http://127.0.0.1:8008/400'; + public const TEST_SERVER = TEST_SERVER; + public const TEST_URL = 'http://127.0.0.1:8008'; + public const TEST_URL_400 = 'http://127.0.0.1:8008/400'; - const SAMPLE_JSON_HEADER = + public const SAMPLE_JSON_HEADER = "HTTP/1.1 200 OK Content-Type: application/json Connection: keep-alive Transfer-Encoding: chunked\r\n"; - const SAMPLE_JSON_HEADER_LOWERCASE = + public const SAMPLE_JSON_HEADER_LOWERCASE = "HTTP/2 200 date: Tue, 07 Jan 2020 09:11:21 GMT content-type: application/json @@ -41,29 +41,29 @@ class HttpfulTest extends \PHPUnit\Framework\TestCase access-control-allow-methods: GET, POST, PUT, PATCH, DELETE access-control-allow-headers: Authorization, Content-Type, Accept-Encoding, Cache-Control, DNT cache-control: private, must-revalidate\r\n"; - const SAMPLE_JSON_RESPONSE = '{"key":"value","object":{"key":"value"},"array":[1,2,3,4]}'; - const SAMPLE_CSV_HEADER = + public const SAMPLE_JSON_RESPONSE = '{"key":"value","object":{"key":"value"},"array":[1,2,3,4]}'; + public const SAMPLE_CSV_HEADER = "HTTP/1.1 200 OK Content-Type: text/csv Connection: keep-alive Transfer-Encoding: chunked\r\n"; - const SAMPLE_CSV_RESPONSE = + public const SAMPLE_CSV_RESPONSE = "Key1,Key2 Value1,Value2 \"40.0\",\"Forty\""; - const SAMPLE_XML_RESPONSE = '2a stringTRUE'; - const SAMPLE_XML_HEADER = + public const SAMPLE_XML_RESPONSE = '2a stringTRUE'; + public const SAMPLE_XML_HEADER = "HTTP/1.1 200 OK Content-Type: application/xml Connection: keep-alive Transfer-Encoding: chunked\r\n"; - const SAMPLE_VENDOR_HEADER = + public const SAMPLE_VENDOR_HEADER = "HTTP/1.1 200 OK Content-Type: application/vnd.nategood.message+xml Connection: keep-alive Transfer-Encoding: chunked\r\n"; - const SAMPLE_VENDOR_TYPE = "application/vnd.nategood.message+xml"; - const SAMPLE_MULTI_HEADER = + public const SAMPLE_VENDOR_TYPE = "application/vnd.nategood.message+xml"; + public const SAMPLE_MULTI_HEADER = "HTTP/1.1 200 OK Content-Type: application/json Connection: keep-alive @@ -74,8 +74,8 @@ class HttpfulTest extends \PHPUnit\Framework\TestCase function testInit() { $r = Request::init(); - // Did we get a 'Request' object? - $this->assertEquals('Httpful\Request', get_class($r)); + // Did we get a 'Request' object? + $this->assertEquals(\Httpful\Request::class, get_class($r)); } function testDetermineLength() @@ -90,11 +90,11 @@ function testDetermineLength() function testMethods() { - $valid_methods = array('get', 'post', 'delete', 'put', 'options', 'head'); + $valid_methods = ['get', 'post', 'delete', 'put', 'options', 'head']; $url = 'http://example.com/'; - foreach ($valid_methods as $method) { - $r = call_user_func(array('Httpful\Request', $method), $url); - $this->assertEquals('Httpful\Request', get_class($r)); + foreach ($valid_methods as $method) { + $r = call_user_func([\Httpful\Request::class, $method], $url); + $this->assertEquals(\Httpful\Request::class, get_class($r)); $this->assertEquals(strtoupper($method), $r->method); } } @@ -344,10 +344,10 @@ function testParsingContentTypeUpload() } function testAttach() { - $req = Request::init(); - $testsPath = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..'); - $filename = $testsPath . DIRECTORY_SEPARATOR . 'test_image.jpg'; - $req->attach(array('index' => $filename)); + $req = Request::init(); + $testsPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..'); + $filename = $testsPath . DIRECTORY_SEPARATOR . 'test_image.jpg'; + $req->attach(['index' => $filename]); $payload = $req->payload['index']; // PHP 5.5 + will take advantage of CURLFile while previous // versions just use the string syntax @@ -558,7 +558,7 @@ public function testOverrideXmlHandler() // Lazy test... $prev = \Httpful\Httpful::get(\Httpful\Mime::XML); $this->assertEquals($prev, new \Httpful\Handlers\XmlHandler()); - $conf = array('namespace' => 'http://example.com'); + $conf = ['namespace' => 'http://example.com']; \Httpful\Httpful::register(\Httpful\Mime::XML, new \Httpful\Handlers\XmlHandler($conf)); $new = \Httpful\Httpful::get(\Httpful\Mime::XML); $this->assertNotEquals($prev, $new); @@ -589,12 +589,12 @@ public function testParseJSON() { $handler = new JsonHandler(); - $bodies = array( + $bodies = [ 'foo', - array(), - array('foo', 'bar'), + [], + ['foo', 'bar'], null - ); + ]; foreach ($bodies as $body) { $this->assertEquals($body, $handler->parse(json_encode($body))); } diff --git a/tests/bootstrap-server.php b/tests/bootstrap-server.php index 1c27bd9..1ac0dad 100644 --- a/tests/bootstrap-server.php +++ b/tests/bootstrap-server.php @@ -1,7 +1,7 @@ ./server.log 2>&1 & echo $!', WEB_SERVER_HOST, WEB_SERVER_PORT, WEB_SERVER_DOCROOT); // Execute the command and store the process ID - $output = array(); + $output = []; exec($command, $output, $exit_code); // sleep for a second to let server come up From 2d2d9255d77f7adecce6a5a3a98c6c2909c3ca2a Mon Sep 17 00:00:00 2001 From: sosherof Date: Fri, 12 May 2023 07:19:41 -0700 Subject: [PATCH 2/3] Fixing some type-o's. --- downloads/httpful.phar | Bin 69013 -> 69018 bytes src/Httpful/Handlers/JsonHandler.php | 2 +- src/Httpful/Handlers/XmlHandler.php | 8 ++++---- src/Httpful/Mime.php | 6 +++--- src/Httpful/Response/Headers.php | 9 ++++++--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/downloads/httpful.phar b/downloads/httpful.phar index 9a7ce6cde1de58c83944bc34e1d90cf635c24ee8..33b8a20d2269e5e0b87eeee1803626fea76e1297 100644 GIT binary patch delta 384 zcmbO_n`PE)mI?ouOFZHxGcvk^X>UeHFx}5+0j5teT7qddCQ|`*76t~O+7u9-^7v-= zWN#*Ouw*NfF__-XWCf;wFqsG(5`-uQ(P>(HZ6@0=D}W{AnRUQ)AG4}}7&}A}h}OBm zYc}~Xvm#jXIaHAti=luP7eo<=Zr}4xY;rh@3P{oBI+hI*lXFESCkNQFZ+4U2DKz<~ zgyd!c0~2O;D}}_OqQuI{^>w0~BaP!&-~#`@N^iboev=Ut@ w$!TmmvT@du3|_t5mrL8X=sCGQx+&9`ws$>WfBR)Im&E7U%nS?+?oPf=05!aVkpKVy delta 362 zcmbO=n`P>3mI?ouGgV?IGcvk^X>UeHFx}5+0j5teT7qddCQ|`<76t~O+7u97{o?P{ z$=*!nV98b{V=%p&$qG#WU@{R{DhN>wq8Ah=1x~hMRsc)JGwXoqK4w(`Q+9|V5dEW3 z?bqbP%!**i=TJprEQSKwTo6Sd+T=@s)Z}m$6_BFMbu1esCLhX@*z6~}Q)n~4fh+Um znJ)!5=NKoku=8>$073QSLSB*0AIxtuZoXi7O=R*~Kds3d{k63e>=lYrbJDD=RB|(O zQ;VZjiZk+yO5*bpb5mm#tQ3&AlLPgXCpYABOxE%b18Lv9(cgVOqsHbR@2cc9YV`hZ qY`MgG_lxN4D#24V0URw3iopenMemory(); @@ -90,7 +90,7 @@ public function serialize_node(&$xmlw, $node) { /** * @author Zack Douglas */ - private function _future_serializeAsXml($value, $node = null, $dom = null) + private function _future_serializeAsXml($value, $node = null, $dom = null): array { if (!$dom) { $dom = new \DOMDocument; @@ -121,7 +121,7 @@ private function _future_serializeAsXml($value, $node = null, $dom = null) /** * @author Zack Douglas */ - private function _future_serializeArrayAsXml($value, &$parent, &$dom) + private function _future_serializeArrayAsXml($value, &$parent, &$dom): array { foreach ($value as $k => &$v) { $n = $k; @@ -137,7 +137,7 @@ private function _future_serializeArrayAsXml($value, &$parent, &$dom) /** * @author Zack Douglas */ - private function _future_serializeObjectAsXml($value, &$parent, &$dom) + private function _future_serializeObjectAsXml($value, &$parent, &$dom): array { $refl = new \ReflectionObject($value); foreach ($refl->getProperties() as $pr) { diff --git a/src/Httpful/Mime.php b/src/Httpful/Mime.php index 3965075..137ec79 100644 --- a/src/Httpful/Mime.php +++ b/src/Httpful/Mime.php @@ -44,16 +44,16 @@ class Mime * @param string $short_name common name for mime type (e.g. json) * @return string full mime type (e.g. application/json) */ - public static function getFullMime($short_name): bool + public static function getFullMime(string $short_name): bool { - return array_key_exists($short_name, self::$mimes) ? self::$mimes[$short_name] : $short_name; + return self::$mimes[$short_name] ?? $short_name; } /** * @param string $short_name * @return bool */ - public static function supportsMimeType($short_name): bool + public static function supportsMimeType(string $short_name): bool { return array_key_exists($short_name, self::$mimes); } diff --git a/src/Httpful/Response/Headers.php b/src/Httpful/Response/Headers.php index 63ea6d9..9fdeb8d 100644 --- a/src/Httpful/Response/Headers.php +++ b/src/Httpful/Response/Headers.php @@ -21,9 +21,10 @@ private function __construct($headers) public static function fromString($string) { $headers = preg_split("/(\r|\n)+/", $string, -1, \PREG_SPLIT_NO_EMPTY); - $parse_headers = array(); - for ($i = 1; $i < count($headers); $i++) { - [($key, $raw_value] = explode(':', $headers[$i], 2); + $parse_headers = []; + $headersCount = count($headers); + for ($i = 1; $i < $headersCount; $i++) { + [$key, $raw_value] = explode(':', $headers[$i], 2); $key = trim($key); $value = trim($raw_value); if (array_key_exists($key, $parse_headers)) { @@ -61,6 +62,7 @@ public function offsetGet($offset) * @param string $offset * @param string $value * @throws \Exception + * @return never */ public function offsetSet($offset, $value) { @@ -70,6 +72,7 @@ public function offsetSet($offset, $value) /** * @param string $offset * @throws \Exception + * @return never */ public function offsetUnset($offset) { From c3fdcd1b1757927ca9d662279cda4989a8fb71ba Mon Sep 17 00:00:00 2001 From: sosherof Date: Fri, 12 May 2023 07:19:41 -0700 Subject: [PATCH 3/3] Fixing some type-o's. --- .gitignore | 2 ++ downloads/httpful.phar | Bin 69013 -> 69227 bytes src/Httpful/Handlers/JsonHandler.php | 2 +- src/Httpful/Handlers/XmlHandler.php | 8 ++++---- src/Httpful/Mime.php | 8 ++++---- src/Httpful/Request.php | 11 ++++++----- src/Httpful/Response.php | 7 +++---- src/Httpful/Response/Headers.php | 14 ++++++++++---- 8 files changed, 30 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 7b39a0b..5cbf483 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ vendor downloads .idea/* tests/.phpunit.result.cache +/rector.php +/.vs diff --git a/downloads/httpful.phar b/downloads/httpful.phar index 9a7ce6cde1de58c83944bc34e1d90cf635c24ee8..5e0d6009a7f501d4edead489277a0a4281c3ae93 100644 GIT binary patch delta 849 zcmbO_o8|Q!mI?oucZtPMW@K~+)834ZV7i~t0!*J`v;@;^Or`?rEDQ`lwJ9Jv2W#8;3yHjZLPYKD*0tP0`>{beiMMa5~lk4k5H%A)BvA_lXf0f>R z$^0fGOkneB%WEQ9#U(|VdFcu&#TofUCGmNQxv82~3J^hFE(IW{1`!}IdBH1jC6(OF z+|=S|B;~OR_V&oyCvSYKGg-$!lpSjF=0^XejFVsai*2?Gl+@#}hYC+tY!IJ3p^j&A zRlWb@gXs#BWAgZ!h2GyfueqCi|ZdXLU?YPA!<6e?oL~^2t|% z91v##9k%eJ=;ox`uENUEvDOergQQe4QWH~Bi;A7|OY=$;Y!#A0w8rGZvm%psz7tYK zk+xP)$<)@?RH#O12N@B)`SZIK%##D|uuoq6Nn1iWIwmN!q_ik6q_QA2JToW9IU_MI zJvDZ6VzJodd!P22DmWB@-DNYjz%3 zv?k@JR89_DCAxX*KV#;}4Z@<+e={bx0Eq6Ffh0~`8ojraY8H? delta 586 zcmaDohh^$)mI?ouGgV?IGcvk^X>UeHFx}5+0j5teT7qddCQ|`<76t~O+7u97{o?P{ z$=*!nV98b{V=%p&$qG#WU@{R{DhN>wq8Ah=1x~hMRsc)JGwXoqK4w(`Q+9|V5dEW3 z?bqbP%!**i=gb-c6J|psLA31W-#;hIvuFrtb3p__w8@tMsmb9i3IdbGAc7!z&peGe zo7-8IOH4lWN@BC0>`tM{O@%_66%CA;CtE%hoP6Lu%jN>(IF`xhze#WYV1APkEd9vx zh{)uL{-I0?_LCp@Ni$ka{_EGfd7}SP#>uxlBsTj5O6pB^YIdKzrCxioZVkueTnUaz zZ9FYGO)iQE{}oV{&q8 zL5X^-f~~EsLSAW3j;2C2FV|$f4`Q49PCgKvEL<+Qx&5}MFk50#QDUXWHiSfkbdOptWiopenMemory(); @@ -90,7 +90,7 @@ public function serialize_node(&$xmlw, $node) { /** * @author Zack Douglas */ - private function _future_serializeAsXml($value, $node = null, $dom = null) + private function _future_serializeAsXml($value, $node = null, $dom = null): array { if (!$dom) { $dom = new \DOMDocument; @@ -121,7 +121,7 @@ private function _future_serializeAsXml($value, $node = null, $dom = null) /** * @author Zack Douglas */ - private function _future_serializeArrayAsXml($value, &$parent, &$dom) + private function _future_serializeArrayAsXml($value, &$parent, &$dom): array { foreach ($value as $k => &$v) { $n = $k; @@ -137,7 +137,7 @@ private function _future_serializeArrayAsXml($value, &$parent, &$dom) /** * @author Zack Douglas */ - private function _future_serializeObjectAsXml($value, &$parent, &$dom) + private function _future_serializeObjectAsXml($value, &$parent, &$dom): array { $refl = new \ReflectionObject($value); foreach ($refl->getProperties() as $pr) { diff --git a/src/Httpful/Mime.php b/src/Httpful/Mime.php index 3965075..bd72396 100644 --- a/src/Httpful/Mime.php +++ b/src/Httpful/Mime.php @@ -44,16 +44,16 @@ class Mime * @param string $short_name common name for mime type (e.g. json) * @return string full mime type (e.g. application/json) */ - public static function getFullMime($short_name): bool - { - return array_key_exists($short_name, self::$mimes) ? self::$mimes[$short_name] : $short_name; + public static function getFullMime(string $short_name): string + { + return self::$mimes[$short_name] ?? $short_name; } /** * @param string $short_name * @return bool */ - public static function supportsMimeType($short_name): bool + public static function supportsMimeType(string $short_name): bool { return array_key_exists($short_name, self::$mimes); } diff --git a/src/Httpful/Request.php b/src/Httpful/Request.php index 5e9aae8..e7b91c8 100644 --- a/src/Httpful/Request.php +++ b/src/Httpful/Request.php @@ -1,5 +1,4 @@ expected_type = Mime::getFullMime($mime); + return $this; } // @alias of expects - public function expectsType($mime) + public function expectsType(?string $mime) { return $this->expects($mime); } @@ -749,6 +749,7 @@ public function __call($method, $args) // throw new \Exception("Unsupported Content-Type $mime"); // } } + if (substr($method, 0, 7) === 'expects') { $mime = strtolower(substr($method, 7)); if (Mime::supportsMimeType($mime)) { @@ -947,7 +948,7 @@ public function _curlPrep() $headers[] = "Content-Type: {$this->content_type}"; // allow custom Accept header if set - if ($this->headers['Accept'] === null) { + if (!isset($this->headers['Accept'])) { // http://pretty-rfc.herokuapp.com/RFC2616#header.accept $accept = 'Accept: */*; q=0.5, text/plain; q=0.8, text/html;level=3;'; @@ -1086,7 +1087,7 @@ public function buildResponse($result) { $body = array_pop($response); $headers = array_pop($response); - + return new Response($body, $headers, $this, $info); } diff --git a/src/Httpful/Response.php b/src/Httpful/Response.php index bdfd11a..2e1d204 100644 --- a/src/Httpful/Response.php +++ b/src/Httpful/Response.php @@ -9,7 +9,6 @@ */ class Response { - public $body, $raw_body, $headers, @@ -79,7 +78,7 @@ public function hasBody(): bool * @param string Http response body * @return mixed (array|string|object) the response parse accordingly */ - public function _parse($body) + public function _parse(string $body) { // If the user decided to forgo the automatic // smart parsing, short circuit. @@ -98,13 +97,13 @@ public function _parse($body) // 3. If provided, use the "parent type" of the mime type from the response // 4. Default to the content-type provided in the response $parse_with = $this->request->expected_type; + if (empty($this->request->expected_type)) { $parse_with = Httpful::hasParserRegistered($this->content_type) ? $this->content_type : $this->parent_type; } - - return Httpful::get($parse_with)->parse($body); + return Httpful::get($parse_with)->parse($body); } /** diff --git a/src/Httpful/Response/Headers.php b/src/Httpful/Response/Headers.php index 63ea6d9..32438b7 100644 --- a/src/Httpful/Response/Headers.php +++ b/src/Httpful/Response/Headers.php @@ -21,9 +21,10 @@ private function __construct($headers) public static function fromString($string) { $headers = preg_split("/(\r|\n)+/", $string, -1, \PREG_SPLIT_NO_EMPTY); - $parse_headers = array(); - for ($i = 1; $i < count($headers); $i++) { - [($key, $raw_value] = explode(':', $headers[$i], 2); + $parse_headers = []; + $headersCount = count($headers); + for ($i = 1; $i < $headersCount; $i++) { + [$key, $raw_value] = explode(':', $headers[$i], 2); $key = trim($key); $value = trim($raw_value); if (array_key_exists($key, $parse_headers)) { @@ -49,9 +50,10 @@ public function offsetExists($offset): bool } /** - * @param string $offset + * @param mixed $offset * @return mixed */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->getCaseInsensitive($offset); @@ -61,7 +63,9 @@ public function offsetGet($offset) * @param string $offset * @param string $value * @throws \Exception + * @return never */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { throw new \Exception("Headers are read-only."); @@ -70,7 +74,9 @@ public function offsetSet($offset, $value) /** * @param string $offset * @throws \Exception + * @return never */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { throw new \Exception("Headers are read-only.");