comments and formatting
authorgggeek <giunta.gaetano@gmail.com>
Mon, 4 Jan 2021 22:52:53 +0000 (22:52 +0000)
committergggeek <giunta.gaetano@gmail.com>
Mon, 4 Jan 2021 22:52:53 +0000 (22:52 +0000)
src/Encoder.php
src/Helper/Charset.php
src/Helper/Http.php
src/Helper/Logger.php
src/Request.php
src/Response.php
src/Value.php

index c7f44d5..d352831 100644 (file)
@@ -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'];
index 3440fc6..8fdecb1 100644 (file)
@@ -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);
         }
     }
-
 }
index d029a0e..ecf2d48 100644 (file)
@@ -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'
index b022311..bee7b08 100644 (file)
@@ -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
      */
index 655344c..82f2b79 100644 (file)
@@ -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
index a7b9492..d428c17 100644 (file)
@@ -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()
     {
index 6bcb8b4..e3db3a1 100644 (file)
@@ -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()
     {