Conditions | 14 |
Paths | 16 |
Total Lines | 46 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
42 | protected function arrayToXml(array &$data, SimpleXMLElement $xmlData) |
||
43 | { |
||
44 | foreach ($data as $key => $value) { |
||
45 | $key = ltrim($key, '_'); |
||
46 | if (\is_array($value)) { |
||
47 | if (\is_numeric($key)) { |
||
48 | $key = 'resource'; |
||
49 | } |
||
50 | if (false === empty($value[XmlTransformer::LINKS_HREF])) { |
||
51 | $subnode = $xmlData->addChild('link'); |
||
52 | $subnode->addAttribute('rel', $key); |
||
53 | foreach ($this->linkKeys as $linkKey) { |
||
54 | if (!empty($value[$linkKey])) { |
||
55 | $subnode->addAttribute($linkKey, $value[$linkKey]); |
||
56 | } |
||
57 | } |
||
58 | } else { |
||
59 | if (!empty($value[XmlTransformer::LINKS][XmlTransformer::LINKS_HREF])) { |
||
60 | $subnode = $xmlData->addChild('resource'); |
||
61 | $subnode->addAttribute( |
||
62 | XmlTransformer::LINKS_HREF, |
||
63 | $value[XmlTransformer::LINKS][XmlTransformer::LINKS_HREF] |
||
64 | ); |
||
65 | if ($key !== 'resource') { |
||
66 | $subnode->addAttribute('rel', $key); |
||
67 | } |
||
68 | } else { |
||
69 | $subnode = $xmlData->addChild($key); |
||
70 | } |
||
71 | } |
||
72 | $this->arrayToXml($value, $subnode); |
||
73 | } else { |
||
74 | if ($key !== XmlTransformer::LINKS) { |
||
75 | if ($value === true || $value === false) { |
||
76 | $value = ($value) ? 'true' : 'false'; |
||
77 | } |
||
78 | |||
79 | if ($key === XmlTransformer::LINKS_HREF) { |
||
80 | break; |
||
81 | } |
||
82 | |||
83 | $xmlData->addChild("$key", '<![CDATA['.html_entity_decode($value).']]>'); |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 |