Remove usage of 'each' call from tests to make them work w. php 7.2; fix an error...
authorgggeek <giunta.gaetano@gmail.com>
Sat, 20 Jan 2018 14:06:06 +0000 (14:06 +0000)
committergggeek <giunta.gaetano@gmail.com>
Sat, 20 Jan 2018 14:06:06 +0000 (14:06 +0000)
src/Client.php
src/Encoder.php
src/Server.php
src/Value.php
src/Wrapper.php
tests/1ParsingBugsTest.php

index 4279ebc..101068b 100644 (file)
@@ -537,7 +537,6 @@ class Client
                 $this->proxy_pass,
                 $this->proxy_authtype,
                 $method,
-                $this->keepalive,
                 $this->key,
                 $this->keypass,
                 $this->sslversion
@@ -569,7 +568,7 @@ class Client
         $method='http')
     {
         return $this->sendPayloadSocket($req, $server, $port, $timeout, $username, $password, $authType, null, null,
-            null, null, $proxyHost, $proxyPort, $proxyUsername, $proxyPassword, $proxyAuthType);
+            null, null, $proxyHost, $proxyPort, $proxyUsername, $proxyPassword, $proxyAuthType, $method);
     }
 
     /**
@@ -645,6 +644,7 @@ class Client
 
         $payload = $req->payload;
         // Deflate request body and set appropriate request headers
+        $encodingHdr = '';
         if (function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate')) {
             if ($this->request_compression == 'gzip') {
                 $a = @gzencode($payload);
@@ -659,8 +659,6 @@ class Client
                     $encodingHdr = "Content-Encoding: deflate\r\n";
                 }
             }
-        } else {
-            $encodingHdr = '';
         }
 
         // thanks to Grant Rauscher <grant7@firstworld.net> for this
@@ -1260,10 +1258,12 @@ class Client
                         break;
                     case 'struct':
                         $code = $val['faultCode'];
+                        /** @var Value $code */
                         if ($code->kindOf() != 'scalar' || $code->scalartyp() != 'int') {
                             return false;
                         }
                         $str = $val['faultString'];
+                        /** @var Value $str */
                         if ($str->kindOf() != 'scalar' || $str->scalartyp() != 'string') {
                             return false;
                         }
index 495584d..b015115 100644 (file)
@@ -6,6 +6,7 @@ use PhpXmlRpc\Helper\XMLParser;
 
 /**
  * A helper class to easily convert between Value objects and php native values
+ * @todo implement an interface
  */
 class Encoder
 {
@@ -292,7 +293,9 @@ class Encoder
             case 'methodresponse':
                 $v = &$xmlRpcParser->_xh['value'];
                 if ($xmlRpcParser->_xh['isf'] == 1) {
+                    /** @var Value $vc */
                     $vc = $v['faultCode'];
+                    /** @var Value $vs */
                     $vs = $v['faultString'];
                     $r = new Response(0, $vc->scalarval(), $vs->scalarval());
                 } else {
index ab17168..49a5483 100644 (file)
@@ -825,12 +825,22 @@ class Server
         return $outAr;
     }
 
+    /**
+     * @param Server $server
+     * @param Request $req
+     * @return Response
+     */
     public static function _xmlrpcs_getCapabilities($server, $req = null)
     {
         $encoder = new Encoder();
         return new Response($encoder->encode($server->getCapabilities()));
     }
 
+    /**
+     * @param Server $server
+     * @param Request $req
+     * @return Response
+     */
     public static function _xmlrpcs_listMethods($server, $req = null) // if called in plain php values mode, second param is missing
     {
         $outAr = array();
@@ -846,6 +856,11 @@ class Server
         return new Response(new Value($outAr, 'array'));
     }
 
+    /**
+     * @param Server $server
+     * @param Request $req
+     * @return Response
+     */
     public static function _xmlrpcs_methodSignature($server, $req)
     {
         // let accept as parameter both an xmlrpc value or string
@@ -883,6 +898,11 @@ class Server
         return $r;
     }
 
+    /**
+     * @param Server $server
+     * @param Request $req
+     * @return Response
+     */
     public static function _xmlrpcs_methodHelp($server, $req)
     {
         // let accept as parameter both an xmlrpc value or string
@@ -926,6 +946,11 @@ class Server
         return new Value($struct, 'struct');
     }
 
+    /**
+     * @param Server $server
+     * @param Value $call
+     * @return Value
+     */
     public static function _xmlrpcs_multicall_do_call($server, $call)
     {
         if ($call->kindOf() != 'struct') {
@@ -969,6 +994,11 @@ class Server
         return new Value(array($result->value()), 'array');
     }
 
+    /**
+     * @param Server $server
+     * @param Value $call
+     * @return Value
+     */
     public static function _xmlrpcs_multicall_do_call_phpvals($server, $call)
     {
         if (!is_array($call)) {
@@ -1008,6 +1038,11 @@ class Server
         return new Value(array($result->value()), 'array');
     }
 
+    /**
+     * @param Server $server
+     * @param Request $req
+     * @return Response
+     */
     public static function _xmlrpcs_multicall($server, $req)
     {
         $result = array();
index 8747e69..ae73aaa 100644 (file)
@@ -296,6 +296,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
                     $rs .= "<struct>\n";
                 }
                 $charsetEncoder = Charset::instance();
+                /** @var Value $val2 */
                 foreach ($val as $key2 => $val2) {
                     $rs .= '<member><name>' . $charsetEncoder->encodeEntities($key2, PhpXmlRpc::$xmlrpc_internalencoding, $charsetEncoding) . "</name>\n";
                     //$rs.=$this->serializeval($val2);
@@ -307,6 +308,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
             case 2:
                 // array
                 $rs .= "<array>\n<data>\n";
+                /** @var Value $element */
                 foreach ($val as $element) {
                     //$rs.=$this->serializeval($val[$i]);
                     $rs .= $element->serialize($charsetEncoding);
@@ -480,7 +482,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
     /**
      * Implements the IteratorAggregate interface
      *
-     * @return ArrayIterator
+     * @return \ArrayIterator
      */
     public function getIterator() {
         switch ($this->mytype) {
@@ -493,7 +495,6 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
             default:
                 return new \ArrayIterator();
         }
-        return new \ArrayIterator();
     }
 
     public function offsetSet($offset, $value) {
index a45100b..bcdd5ef 100644 (file)
@@ -110,7 +110,7 @@ class Wrapper
      * Since php is a typeless language, to infer types of input and output parameters,
      * it relies on parsing the javadoc-style comment block associated with the given
      * function. Usage of xmlrpc native types (such as datetime.dateTime.iso8601 and base64)
-     * in the @param tag is also allowed, if you need the php function to receive/send
+     * in the '@param' tag is also allowed, if you need the php function to receive/send
      * data in that particular format (note that base64 encoding/decoding is transparently
      * carried out by the lib, while datetime vals are passed around as strings)
      *
@@ -396,11 +396,15 @@ class Wrapper
      * @param $callable
      * @param array $extraOptions
      * @param string $plainFuncName
-     * @param string $funcDesc
+     * @param array $funcDesc
      * @return \Closure
      */
     protected function buildWrapFunctionClosure($callable, $extraOptions, $plainFuncName, $funcDesc)
     {
+        /**
+         * @param Request $req
+         * @return mixed
+         */
         $function = function($req) use($callable, $extraOptions, $funcDesc)
         {
             $nameSpace = '\\PhpXmlRpc\\';
@@ -785,7 +789,7 @@ class Wrapper
      * @param Client $client
      * @param string $methodName
      * @param array $extraOptions
-     * @param string $mSig
+     * @param array $mSig
      * @return \Closure
      *
      * @todo should we allow usage of parameter simple_client_copy to mean 'do not clone' in this case?
index ce463f7..e85586d 100644 (file)
@@ -629,11 +629,13 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
         $v2 = new \PhpXmlRpc\Value(array(new \PhpXmlRpc\Value('one'), new \PhpXmlRpc\Value('two')), 'array');
         $this->assertequals(2, count($v2));
         $out = array(0 => 'object', 1 => 'object');
+        $i = 0;
         foreach($v2 as $key => $val)
         {
-            $expected = each($out);
+            $expected = $out[$i];
             $this->assertequals($expected['key'], $key);
             $this->assertequals($expected['value'], gettype($val));
+            $i++;
         }
     }
 }