Completed
Push — master ( f92bdf...7df27d )
by Gaetano
08:05
created

Encoder::decode()   D

Complexity

Conditions 20
Paths 19

Size

Total Lines 81
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 33
CRAP Score 56.4499

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 20
eloc 52
nc 19
nop 2
dl 0
loc 81
ccs 33
cts 60
cp 0.55
crap 56.4499
rs 4.9645
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PhpXmlRpc;
4
5
use PhpXmlRpc\Helper\XMLParser;
6
7
/**
8
 * A helper class to easily convert between Value objects and php native values
9
 */
10
class Encoder
11
{
12
    /**
13
     * Takes an xmlrpc value in object format and translates it into native PHP types.
14
     *
15
     * Works with xmlrpc requests objects as input, too.
16
     *
17
     * Given proper options parameter, can rebuild generic php object instances
18
     * (provided those have been encoded to xmlrpc format using a corresponding
19
     * option in php_xmlrpc_encode())
20
     * PLEASE NOTE that rebuilding php objects involves calling their constructor function.
21
     * This means that the remote communication end can decide which php code will
22
     * get executed on your server, leaving the door possibly open to 'php-injection'
23
     * style of attacks (provided you have some classes defined on your server that
24
     * might wreak havoc if instances are built outside an appropriate context).
25
     * Make sure you trust the remote server/client before eanbling this!
26
     *
27
     * @author Dan Libby ([email protected])
28
     *
29
     * @param Value|Request $xmlrpcVal
30
     * @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects; if 'dates_as_objects' is set xmlrpc datetimes are decoded as php DateTime objects (standard is
31
     *
32
     * @return mixed
33
     */
34 231
    public function decode($xmlrpcVal, $options = array())
35
    {
36 231
        switch ($xmlrpcVal->kindOf()) {
37 231
            case 'scalar':
38 231
                if (in_array('extension_api', $options)) {
39
                    $val = reset($xmlrpcVal->me);
40
                    $typ = key($xmlrpcVal->me);
41
                    switch ($typ) {
42
                        case 'dateTime.iso8601':
43
                            $xmlrpcVal->scalar = $val;
44
                            $xmlrpcVal->type = 'datetime';
45
                            $xmlrpcVal->timestamp = \PhpXmlRpc\Helper\Date::iso8601Decode($val);
46
47
                            return $xmlrpcVal;
48
                        case 'base64':
49
                            $xmlrpcVal->scalar = $val;
50
                            $xmlrpcVal->type = $typ;
51
52
                            return $xmlrpcVal;
53
                        default:
54
                            return $xmlrpcVal->scalarval();
0 ignored issues
show
Bug introduced by
The method scalarval does only exist in PhpXmlRpc\Value, but not in PhpXmlRpc\Request.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
55
                    }
56
                }
57 231
                if (in_array('dates_as_objects', $options) && $xmlrpcVal->scalartyp() == 'dateTime.iso8601') {
0 ignored issues
show
Bug introduced by
The method scalartyp does only exist in PhpXmlRpc\Value, but not in PhpXmlRpc\Request.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
58
                    // we return a Datetime object instead of a string
59
                    // since now the constructor of xmlrpc value accepts safely strings, ints and datetimes,
60
                    // we cater to all 3 cases here
61
                    $out = $xmlrpcVal->scalarval();
62
                    if (is_string($out)) {
63
                        $out = strtotime($out);
64
                    }
65
                    if (is_int($out)) {
66
                        $result = new \DateTime();
67
                        $result->setTimestamp($out);
68
69
                        return $result;
70
                    } elseif (is_a($out, 'DateTimeInterface')) {
71
                        return $out;
72
                    }
73
                }
74
75 231
                return $xmlrpcVal->scalarval();
76 231
            case 'array':
77 96
                $arr = array();
78 96
                foreach($xmlrpcVal as $value) {
0 ignored issues
show
Bug introduced by
The expression $xmlrpcVal of type object<PhpXmlRpc\Value>|object<PhpXmlRpc\Request> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
79 96
                    $arr[] = $this->decode($value, $options);
80 96
                }
81
82 96
                return $arr;
83 174
            case 'struct':
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
84
                // If user said so, try to rebuild php objects for specific struct vals.
85
                /// @todo should we raise a warning for class not found?
86
                // shall we check for proper subclass of xmlrpc value instead of
87
                // presence of _php_class to detect what we can do?
88 58
                if (in_array('decode_php_objs', $options) && $xmlrpcVal->_php_class != ''
89 39
                    && class_exists($xmlrpcVal->_php_class)
90 39
                ) {
91 20
                    $obj = @new $xmlrpcVal->_php_class();
92 20
                    foreach ($xmlrpcVal as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $xmlrpcVal of type object<PhpXmlRpc\Value>|object<PhpXmlRpc\Request> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
93 20
                        $obj->$key = $this->decode($value, $options);
94 20
                    }
95
96 20
                    return $obj;
97
                } else {
98 39
                    $arr = array();
99 39
                    foreach ($xmlrpcVal as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $xmlrpcVal of type object<PhpXmlRpc\Value>|object<PhpXmlRpc\Request> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
100 39
                        $arr[$key] = $this->decode($value, $options);
101 39
                    }
102
103 39
                    return $arr;
104
                }
105 117
            case 'msg':
106 117
                $paramCount = $xmlrpcVal->getNumParams();
0 ignored issues
show
Bug introduced by
The method getNumParams does only exist in PhpXmlRpc\Request, but not in PhpXmlRpc\Value.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
107 117
                $arr = array();
108 117
                for ($i = 0; $i < $paramCount; $i++) {
109 117
                    $arr[] = $this->decode($xmlrpcVal->getParam($i), $options);
0 ignored issues
show
Bug introduced by
The method getParam does only exist in PhpXmlRpc\Request, but not in PhpXmlRpc\Value.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
110 117
                }
111
112 117
                return $arr;
113
        }
114
    }
115
116
    /**
117
     * Takes native php types and encodes them into xmlrpc PHP object format.
118
     * It will not re-encode xmlrpc value objects.
119
     *
120
     * Feature creep -- could support more types via optional type argument
121
     * (string => datetime support has been added, ??? => base64 not yet)
122
     *
123
     * If given a proper options parameter, php object instances will be encoded
124
     * into 'special' xmlrpc values, that can later be decoded into php objects
125
     * by calling php_xmlrpc_decode() with a corresponding option
126
     *
127
     * @author Dan Libby ([email protected])
128
     *
129
     * @param mixed $phpVal the value to be converted into an xmlrpc value object
130
     * @param array $options can include 'encode_php_objs', 'auto_dates', 'null_extension' or 'extension_api'
131
     *
132
     * @return \PhpXmlrpc\Value
133
     */
134 216
    public function encode($phpVal, $options = array())
135
    {
136 216
        $type = gettype($phpVal);
137
        switch ($type) {
138 216
            case 'string':
139 213
                if (in_array('auto_dates', $options) && preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $phpVal)) {
140 1
                    $xmlrpcVal = new Value($phpVal, Value::$xmlrpcDateTime);
141 1
                } else {
142 213
                    $xmlrpcVal = new Value($phpVal, Value::$xmlrpcString);
143
                }
144 213
                break;
145 102
            case 'integer':
146 98
                $xmlrpcVal = new Value($phpVal, Value::$xmlrpcInt);
147 98
                break;
148 26
            case 'double':
149 1
                $xmlrpcVal = new Value($phpVal, Value::$xmlrpcDouble);
150 1
                break;
151
            // <G_Giunta_2001-02-29>
152
            // Add support for encoding/decoding of booleans, since they are supported in PHP
153 26
            case 'boolean':
154 1
                $xmlrpcVal = new Value($phpVal, Value::$xmlrpcBoolean);
155 1
                break;
156
            // </G_Giunta_2001-02-29>
157 26
            case 'array':
158
                // PHP arrays can be encoded to either xmlrpc structs or arrays,
159
                // depending on whether they are hashes or plain 0..n integer indexed
160
                // A shorter one-liner would be
161
                // $tmp = array_diff(array_keys($phpVal), range(0, count($phpVal)-1));
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
162
                // but execution time skyrockets!
163 23
                $j = 0;
164 23
                $arr = array();
165 23
                $ko = false;
166 23
                foreach ($phpVal as $key => $val) {
167 23
                    $arr[$key] = $this->encode($val, $options);
168 23
                    if (!$ko && $key !== $j) {
169 22
                        $ko = true;
170 22
                    }
171 23
                    $j++;
172 23
                }
173 23
                if ($ko) {
174 22
                    $xmlrpcVal = new Value($arr, Value::$xmlrpcStruct);
0 ignored issues
show
Documentation introduced by
$arr is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
175 22
                } else {
176 2
                    $xmlrpcVal = new Value($arr, Value::$xmlrpcArray);
0 ignored issues
show
Documentation introduced by
$arr is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
177
                }
178 23
                break;
179 4
            case 'object':
180 2
                if (is_a($phpVal, 'PhpXmlRpc\Value')) {
181 1
                    $xmlrpcVal = $phpVal;
182 2
                } elseif (is_a($phpVal, 'DateTimeInterface')) {
183
                    $xmlrpcVal = new Value($phpVal->format('Ymd\TH:i:s'), Value::$xmlrpcStruct);
184
                } else {
185 1
                    $arr = array();
186 1
                    foreach($phpVal as $k => $v) {
187 1
                        $arr[$k] = $this->encode($v, $options);
188 1
                    }
189 1
                    $xmlrpcVal = new Value($arr, Value::$xmlrpcStruct);
0 ignored issues
show
Documentation introduced by
$arr is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
190 1
                    if (in_array('encode_php_objs', $options)) {
191
                        // let's save original class name into xmlrpc value:
192
                        // might be useful later on...
193 1
                        $xmlrpcVal->_php_class = get_class($phpVal);
194
                    }
195
                }
196 2
                break;
197 2
            case 'NULL':
198 2
                if (in_array('extension_api', $options)) {
199
                    $xmlrpcVal = new Value('', Value::$xmlrpcString);
200 2
                } elseif (in_array('null_extension', $options)) {
201
                    $xmlrpcVal = new Value('', Value::$xmlrpcNull);
202
                } else {
203 2
                    $xmlrpcVal = new Value();
204
                }
205 2
                break;
206
            case 'resource':
207
                if (in_array('extension_api', $options)) {
208
                    $xmlrpcVal = new Value((int)$phpVal, Value::$xmlrpcInt);
209
                } else {
210
                    $xmlrpcVal = new Value();
211
                }
212
                break;
213
            // catch "user function", "unknown type"
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
214
            default:
215
                // giancarlo pinerolo <[email protected]>
216
                // it has to return
217
                // an empty object in case, not a boolean.
218
                $xmlrpcVal = new Value();
219
                break;
220
        }
221
222 216
        return $xmlrpcVal;
223
    }
224
225
    /**
226
     * Convert the xml representation of a method response, method request or single
227
     * xmlrpc value into the appropriate object (a.k.a. deserialize).
228
     *
229
     * @param string $xmlVal
230
     * @param array $options
231
     *
232
     * @return mixed false on error, or an instance of either Value, Request or Response
233
     */
234 3
    public function decodeXml($xmlVal, $options = array())
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
235
    {
236
        // 'guestimate' encoding
237 3
        $valEncoding = XMLParser::guessEncoding('', $xmlVal);
238 3 View Code Duplication
        if ($valEncoding != '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
239
240
            // Since parsing will fail if charset is not specified in the xml prologue,
241
            // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
242
            // The following code might be better for mb_string enabled installs, but
243
            // makes the lib about 200% slower...
244
            //if (!is_valid_charset($valEncoding, array('UTF-8'))
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
245 3
            if (!in_array($valEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($xmlVal)) {
246
                if ($valEncoding == 'ISO-8859-1') {
247
                    $xmlVal = utf8_encode($xmlVal);
248
                } else {
249
                    if (extension_loaded('mbstring')) {
250
                        $xmlVal = mb_convert_encoding($xmlVal, 'UTF-8', $valEncoding);
251
                    } else {
252
                        error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of xml text: ' . $valEncoding);
253
                    }
254
                }
255
            }
256 3
        }
257
258 3
        $parser = xml_parser_create();
259 3
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
260
        // What if internal encoding is not in one of the 3 allowed?
261
        // we use the broadest one, ie. utf8!
262 3 View Code Duplication
        if (!in_array(PhpXmlRpc::$xmlrpc_internalencoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
263
            xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
264
        } else {
265 3
            xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, PhpXmlRpc::$xmlrpc_internalencoding);
266
        }
267
268 3
        $xmlRpcParser = new XMLParser();
269 3
        xml_set_object($parser, $xmlRpcParser);
270
271 3
        xml_set_element_handler($parser, 'xmlrpc_se_any', 'xmlrpc_ee');
272 3
        xml_set_character_data_handler($parser, 'xmlrpc_cd');
273 3
        xml_set_default_handler($parser, 'xmlrpc_dh');
274 3
        if (!xml_parse($parser, $xmlVal, 1)) {
275
            $errstr = sprintf('XML error: %s at line %d, column %d',
276
                xml_error_string(xml_get_error_code($parser)),
277
                xml_get_current_line_number($parser), xml_get_current_column_number($parser));
278
            error_log($errstr);
279
            xml_parser_free($parser);
280
281
            return false;
282
        }
283 3
        xml_parser_free($parser);
284 3
        if ($xmlRpcParser->_xh['isf'] > 1) {
285
            // test that $xmlrpc->_xh['value'] is an obj, too???
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
286
287
            error_log($xmlRpcParser->_xh['isf_reason']);
288
289
            return false;
290
        }
291 3
        switch ($xmlRpcParser->_xh['rt']) {
292 3
            case 'methodresponse':
293 3
                $v = &$xmlRpcParser->_xh['value'];
294 3
                if ($xmlRpcParser->_xh['isf'] == 1) {
295
                    $vc = $v['faultCode'];
296
                    $vs = $v['faultString'];
297
                    $r = new Response(0, $vc->scalarval(), $vs->scalarval());
298
                } else {
299 3
                    $r = new Response($v);
300
                }
301
302 3
                return $r;
303 1
            case 'methodcall':
304 1
                $req = new Request($xmlRpcParser->_xh['method']);
305 1 View Code Duplication
                for ($i = 0; $i < count($xmlRpcParser->_xh['params']); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
306 1
                    $req->addParam($xmlRpcParser->_xh['params'][$i]);
307 1
                }
308
309 1
                return $req;
310 1
            case 'value':
311 1
                return $xmlRpcParser->_xh['value'];
312
            default:
313
                return false;
314
        }
315
    }
316
317
}
318