From dbcb9c168e60ad868fba442452bbddafee7cf684 Mon Sep 17 00:00:00 2001 From: gggeek Date: Mon, 4 Jan 2021 22:52:53 +0000 Subject: [PATCH] comments and formatting --- src/Encoder.php | 23 ++++++++++++----------- src/Helper/Charset.php | 6 ++++-- src/Helper/Http.php | 2 +- src/Helper/Logger.php | 5 +++-- src/Request.php | 9 +++++---- src/Response.php | 4 ++-- src/Value.php | 9 ++++++++- 7 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/Encoder.php b/src/Encoder.php index c7f44d5..d352831 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -74,15 +74,15 @@ class Encoder return $out; } } - return $xmlrpcVal->scalarval(); + case 'array': $arr = array(); foreach($xmlrpcVal as $value) { $arr[] = $this->decode($value, $options); } - return $arr; + case 'struct': // If user said so, try to rebuild php objects for specific struct vals. /// @todo should we raise a warning for class not found? @@ -95,24 +95,24 @@ class Encoder foreach ($xmlrpcVal as $key => $value) { $obj->$key = $this->decode($value, $options); } - return $obj; } else { $arr = array(); foreach ($xmlrpcVal as $key => $value) { $arr[$key] = $this->decode($value, $options); } - return $arr; } + case 'msg': $paramCount = $xmlrpcVal->getNumParams(); $arr = array(); for ($i = 0; $i < $paramCount; $i++) { $arr[] = $this->decode($xmlrpcVal->getParam($i), $options); } - return $arr; + + /// @todo throw on unsupported type } } @@ -131,7 +131,7 @@ class Encoder * @param mixed $phpVal the value to be converted into an xmlrpc value object * @param array $options can include 'encode_php_objs', 'auto_dates', 'null_extension' or 'extension_api' * - * @return \PhpXmlrpc\Value + * @return Value */ public function encode($phpVal, $options = array()) { @@ -243,13 +243,13 @@ class Encoder * Convert the xml representation of a method response, method request or single * xmlrpc value into the appropriate object (a.k.a. deserialize). * - * Q: is this a good name for this method? It does something quite different from 'decode' after all - * (returning objects vs returns plain php values)... + * @todo is this a good name/class for this method? It does something quite different from 'decode' after all + * (returning objects vs returns plain php values)... In fact it belongs rather to a Parser class * * @param string $xmlVal * @param array $options * - * @return mixed false on error, or an instance of either Value, Request or Response + * @return Value|Request|Response|false false on error, or an instance of either Value, Request or Response */ public function decodeXml($xmlVal, $options = array()) { @@ -307,17 +307,18 @@ class Encoder } else { $r = new Response($v); } - return $r; + case 'methodcall': $req = new Request($xmlRpcParser->_xh['method']); for ($i = 0; $i < count($xmlRpcParser->_xh['params']); $i++) { $req->addParam($xmlRpcParser->_xh['params'][$i]); } - return $req; + case 'value': return $xmlRpcParser->_xh['value']; + case 'fault': // EPI api emulation $v = $xmlRpcParser->_xh['value']; diff --git a/src/Helper/Charset.php b/src/Helper/Charset.php index 3440fc6..8fdecb1 100644 --- a/src/Helper/Charset.php +++ b/src/Helper/Charset.php @@ -4,6 +4,9 @@ namespace PhpXmlRpc\Helper; use PhpXmlRpc\PhpXmlRpc; +/** + * @todo implement an interface + */ class Charset { // tables used for transcoding different charsets into us-ascii xml @@ -32,7 +35,7 @@ class Charset /** * This class is singleton for performance reasons. - * @todo can't we just make $xml_iso88591_Entities a static variable instead ? + * @todo should we just make $xml_iso88591_Entities a static variable instead ? * * @return Charset */ @@ -306,5 +309,4 @@ class Charset throw new \Exception('Unsupported charset: ' . $charset); } } - } diff --git a/src/Helper/Http.php b/src/Helper/Http.php index d029a0e..ecf2d48 100644 --- a/src/Helper/Http.php +++ b/src/Helper/Http.php @@ -63,7 +63,7 @@ class Http /** * Parses HTTP an http response headers and separates them from the body. * - * @param string $data the http response,headers and body. It will be stripped of headers + * @param string $data the http response, headers and body. It will be stripped of headers * @param bool $headersProcessed when true, we assume that response inflating and dechunking has been already carried out * * @return array with keys 'headers' and 'cookies' diff --git a/src/Helper/Logger.php b/src/Helper/Logger.php index b022311..bee7b08 100644 --- a/src/Helper/Logger.php +++ b/src/Helper/Logger.php @@ -3,14 +3,15 @@ namespace PhpXmlRpc\Helper; /** - * @todo make constructor private to force users to go through `instance()` + * @todo implement an interface + * @todo make constructor private to force users to go through `instance()` ? */ class Logger { protected static $instance = null; /** - * This class is singleton, so that later we can move to DI patterns. + * This class can be used as singleton, so that later we can move to DI patterns. * * @return Logger */ diff --git a/src/Request.php b/src/Request.php index 655344c..82f2b79 100644 --- a/src/Request.php +++ b/src/Request.php @@ -268,6 +268,7 @@ class Request if ($respEncoding == 'ISO-8859-1') { $data = utf8_encode($data); } else { + if (extension_loaded('mbstring')) { $data = mb_convert_encoding($data, 'UTF-8', $respEncoding); } else { @@ -304,15 +305,15 @@ class Request } // second error check: xml well formed but not xml-rpc compliant elseif ($xmlRpcParser->_xh['isf'] == 2) { + $r = new Response(0, PhpXmlRpc::$xmlrpcerr['invalid_return'], + PhpXmlRpc::$xmlrpcstr['invalid_return'] . ' ' . $xmlRpcParser->_xh['isf_reason']); + if ($this->debug) { /// @todo echo something for user? } - - $r = new Response(0, PhpXmlRpc::$xmlrpcerr['invalid_return'], - PhpXmlRpc::$xmlrpcstr['invalid_return'] . ' ' . $xmlRpcParser->_xh['isf_reason']); } // third error check: parsing of the response has somehow gone boink. - // NB: shall we omit this check, since we trust the parsing code? + /// @todo shall we omit this check, since we trust the parsing code? elseif ($returnType == 'xmlrpcvals' && !is_object($xmlRpcParser->_xh['value'])) { // something odd has happened // and it's time to generate a client side error diff --git a/src/Response.php b/src/Response.php index a7b9492..d428c17 100644 --- a/src/Response.php +++ b/src/Response.php @@ -27,7 +27,7 @@ class Response public $raw_data = ''; /** - * @param mixed $val either a Value object, a php value or the xml serialization of an xmlrpc value (a string) + * @param Value|string|mixed $val either a Value object, a php value or the xml serialization of an xmlrpc value (a string) * @param integer $fCode set it to anything but 0 to create an error response. In that case, $val is discarded * @param string $fString the error string, in case of an error response * @param string $valType The type of $val passed in. Either 'xmlrpcvals', 'phpvals' or 'xml'. Leave empty to let @@ -102,7 +102,7 @@ class Response * It is up to the user-defined code to decide how to use the received cookies, and whether they have to be sent back * with the next request to the server (using Client::setCookie) or not. * - * @return array array of cookies received from the server + * @return array[] array of cookies received from the server */ public function cookies() { diff --git a/src/Value.php b/src/Value.php index 6bcb8b4..e3db3a1 100644 --- a/src/Value.php +++ b/src/Value.php @@ -53,7 +53,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * * When no value or type is passed in, the value is left uninitialized, and the value can be added later. * - * @param mixed $val if passing in an array, all array elements should be PhpXmlRpc\Value themselves + * @param Value[]|mixed $val if passing in an array, all array elements should be PhpXmlRpc\Value themselves * @param string $type any valid xmlrpc type name (lowercase): i4, int, boolean, string, double, dateTime.iso8601, * base64, array, struct, null. * If null, 'string' is assumed. @@ -232,6 +232,12 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess } } + /** + * @param string typ + * @param Value[]|mixed $val + * @param string $charsetEncoding + * @return string + */ protected function serializedata($typ, $val, $charsetEncoding = '') { $rs = ''; @@ -501,6 +507,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess * Implements the IteratorAggregate interface * * @return \ArrayIterator + * @internal required to be public to implement an Interface */ public function getIterator() { -- 2.43.0