finish fixes for removal of 'each'; fix html injection in demo code
[plcapi.git] / src / Encoder.php
index dfec15d..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
 {
@@ -36,8 +37,8 @@ class Encoder
         switch ($xmlrpcVal->kindOf()) {
             case 'scalar':
                 if (in_array('extension_api', $options)) {
-                    reset($xmlrpcVal->me);
-                    list($typ, $val) = each($xmlrpcVal->me);
+                    $val = reset($xmlrpcVal->me);
+                    $typ = key($xmlrpcVal->me);
                     switch ($typ) {
                         case 'dateTime.iso8601':
                             $xmlrpcVal->scalar = $val;
@@ -156,7 +157,7 @@ class Encoder
             // </G_Giunta_2001-02-29>
             case 'array':
                 // PHP arrays can be encoded to either xmlrpc structs or arrays,
-                // depending on wheter they are hashes or plain 0..n integer indexed
+                // depending on whether they are hashes or plain 0..n integer indexed
                 // A shorter one-liner would be
                 // $tmp = array_diff(array_keys($phpVal), range(0, count($phpVal)-1));
                 // but execution time skyrockets!
@@ -183,8 +184,7 @@ class Encoder
                     $xmlrpcVal = new Value($phpVal->format('Ymd\TH:i:s'), Value::$xmlrpcStruct);
                 } else {
                     $arr = array();
-                    reset($phpVal);
-                    while (list($k, $v) = each($phpVal)) {
+                    foreach($phpVal as $k => $v) {
                         $arr[$k] = $this->encode($v, $options);
                     }
                     $xmlrpcVal = new Value($arr, Value::$xmlrpcStruct);
@@ -210,6 +210,7 @@ class Encoder
                 } else {
                     $xmlrpcVal = new Value();
                 }
+                break;
             // catch "user function", "unknown type"
             default:
                 // giancarlo pinerolo <ping@alt.it>
@@ -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 {