Conditions | 7 |
Paths | 5 |
Total Lines | 40 |
Code Lines | 22 |
Lines | 40 |
Ratio | 100 % |
Tests | 0 |
CRAP Score | 56 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | public function parse($xmlString, &$isFault) |
||
20 | { |
||
21 | $response = new \Zend_XmlRpc_Response(); |
||
22 | |||
23 | try { |
||
24 | $response->loadXml($xmlString); |
||
25 | } catch (\Exception $e) { |
||
26 | throw new ParserException($e->getMessage(), $e->getCode(), $e); |
||
27 | } |
||
28 | |||
29 | $isFault = $response->isFault(); |
||
30 | |||
31 | if ($isFault) { |
||
32 | $fault = $response->getFault(); |
||
33 | |||
34 | return [ |
||
35 | 'faultCode' => $fault->getCode(), |
||
36 | 'faultString' => $fault->getMessage(), |
||
37 | ]; |
||
38 | } |
||
39 | |||
40 | $result = $response->getReturnValue(); |
||
41 | |||
42 | $toBeVisited = [&$result]; |
||
43 | |||
44 | while (isset($toBeVisited[0]) && $value = &$toBeVisited[0]) { |
||
45 | $type = gettype($value); |
||
46 | if ($type === 'array') { |
||
47 | foreach ($value as &$element) { |
||
48 | $toBeVisited[] = &$element; |
||
49 | } |
||
50 | |||
51 | reset($value); // Reset all array pointers |
||
52 | } |
||
53 | |||
54 | array_shift($toBeVisited); |
||
55 | } |
||
56 | |||
57 | return $result; |
||
58 | } |
||
59 | } |
||
60 |
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.