Conditions | 19 |
Paths | 239 |
Total Lines | 83 |
Code Lines | 63 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
190 | public static function marshalObject($domElement, $node, $name, $object, $namespace = NULL, $root = false) |
||
191 | { |
||
192 | if (is_null($object)) { |
||
193 | return; |
||
194 | } |
||
195 | if ($root) { |
||
196 | $childNode = $node; |
||
197 | } else { |
||
198 | if ($object->getValue()) { |
||
199 | $val = preg_replace('/&/', '&', $object->getValue()); |
||
200 | if ($object->getType() === 'cdata') { |
||
201 | $childNode = $domElement->createElement($name); |
||
202 | $cdata = $domElement->createCDATASection(strval($val)); |
||
203 | $childNode->appendChild($cdata); |
||
204 | $node->appendChild($nextChild); |
||
205 | } else { |
||
206 | $childNode = $domElement->createElement($name, $val); |
||
207 | } |
||
208 | $node->appendChild($childNode); |
||
209 | } else { |
||
210 | $childNode = $domElement->createElement($name); |
||
211 | $node->appendChild($childNode); |
||
212 | } |
||
213 | if (!empty($namespace)) { |
||
214 | $ns = $domElement->createAttributeNS(null,'xmlns'); |
||
215 | $ns->value = $namespace; |
||
216 | $childNode->appendChild($ns); |
||
217 | } |
||
218 | } |
||
219 | |||
220 | if ($object->areAttributes()) { |
||
221 | $attrs = $object->getAttributes(); |
||
222 | foreach ($attrs as $attrt => $attrv) { |
||
223 | $attrE = $domElement->createAttribute($attrt); |
||
224 | $attrE->value = $attrv; |
||
225 | $childNode->appendChild($attrE); |
||
226 | } |
||
227 | } |
||
228 | |||
229 | if (empty($object->children)) { |
||
230 | return; |
||
231 | } |
||
232 | foreach ($object->children as $child) { |
||
233 | $nameC = $child['name']; |
||
234 | $valueC = $child['value']; |
||
235 | $namespaceC = $child['namespace']; |
||
236 | if (is_scalar($valueC)) { |
||
237 | $cl = strval($valueC); |
||
238 | $nextChild = $domElement->createElement($nameC, $cl); |
||
239 | $childNode->appendChild($nextChild); |
||
240 | if (!empty($namespaceC)) { |
||
241 | $ns = $domElement->createAttributeNS(null,'xmlns'); |
||
242 | $ns->value = $namespaceC; |
||
243 | $nextChild->appendChild($ns); |
||
244 | } |
||
245 | continue; |
||
246 | } |
||
247 | if (gettype($valueC) == 'array') { |
||
248 | foreach ($valueC as $insideValue) { |
||
249 | if (is_object($insideValue)) { |
||
250 | DeviceXMLmain::marshalObject($domElement, $childNode, $nameC, $insideValue, $namespaceC); |
||
251 | } |
||
252 | if (is_scalar($insideValue)) { |
||
253 | if ($child['type'] === 'cdata') { |
||
254 | $nextChild = $domElement->createElement($nameC); |
||
255 | $cdata = $domElement->createCDATASection(strval($insideValue)); |
||
256 | $nextChild->appendChild($cdata); |
||
257 | $childNode->appendChild($nextChild); |
||
258 | } else { |
||
259 | $nextChild = $domElement->createElement($nameC, strval($insideValue)); |
||
260 | $childNode->appendChild($nextChild); |
||
261 | } |
||
262 | if (!empty($namespaceC)) { |
||
263 | $ns = $domElement->createAttributeNS(null,'xmlns'); |
||
264 | $ns->value = $namespaceC; |
||
265 | $nextChild->appendChild($ns); |
||
266 | } |
||
267 | } |
||
268 | } |
||
269 | continue; |
||
270 | } |
||
271 | if (gettype($valueC) == 'object') { |
||
272 | DeviceXMLmain::marshalObject($domElement, $childNode, $nameC, $valueC, $namespaceC); |
||
273 | } |
||
279 |