Conditions | 12 |
Paths | 9 |
Total Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
85 | protected function arrayToXml($data, \SimpleXmlElement $element, $parent = null) |
||
86 | { |
||
87 | foreach ($data as $key => $value) { |
||
88 | if (is_array($value) || $value instanceof \Traversable) { |
||
89 | if (!is_numeric($key)) { |
||
90 | if (count($value) > 0 && isset($value[0])) { |
||
91 | $this->arrayToXml($value, $element, $key); |
||
92 | } else { |
||
93 | $subnode = $element->addChild($key); |
||
94 | $this->arrayToXml($value, $subnode, $key); |
||
95 | } |
||
96 | } else { |
||
97 | $subnode = $element->addChild($parent); |
||
98 | $this->arrayToXml($value, $subnode, $parent); |
||
99 | } |
||
100 | } else { |
||
101 | if (!is_numeric($key)) { |
||
102 | if (substr($key, 0, 1) === '@') { |
||
103 | $element->addAttribute(substr($key, 1), $value); |
||
104 | } elseif ($key === 'value' and count($data) === 1) { |
||
105 | $element[0] = $value; |
||
106 | } elseif (is_bool($value)) { |
||
107 | $element->addChild($key, intval($value)); |
||
108 | } else { |
||
109 | $element->addChild($key, htmlspecialchars($value, ENT_QUOTES)); |
||
110 | } |
||
111 | } else { |
||
112 | $element->addChild($parent, htmlspecialchars($value, ENT_QUOTES)); |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 | |||
155 |
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: