Conditions | 13 |
Paths | 13 |
Total Lines | 47 |
Code Lines | 28 |
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 |
||
65 | private function arrayToXml(array &$data, SimpleXMLElement $xmlData) |
||
66 | { |
||
67 | foreach ($data as $key => $value) { |
||
68 | $key = ltrim($key, '_'); |
||
69 | |||
70 | if (\is_array($value)) { |
||
71 | if (\is_numeric($key)) { |
||
72 | $key = 'resource'; |
||
73 | } |
||
74 | |||
75 | if (false === empty($value[JsonTransformer::LINKS_HREF])) { |
||
76 | $subnode = $xmlData->addChild('link'); |
||
77 | $subnode->addAttribute('rel', $key); |
||
78 | |||
79 | foreach ($this->linkKeys as $linkKey) { |
||
80 | if (!empty($value[$linkKey])) { |
||
81 | $subnode->addAttribute($linkKey, $value[$linkKey]); |
||
82 | } |
||
83 | } |
||
84 | } else { |
||
85 | if (!empty($value[JsonTransformer::LINKS_KEY][JsonTransformer::SELF_LINK][JsonTransformer::LINKS_HREF])) { |
||
86 | $subnode = $xmlData->addChild('resource'); |
||
87 | $subnode->addAttribute( |
||
88 | JsonTransformer::LINKS_HREF, |
||
89 | $value[JsonTransformer::LINKS_KEY][JsonTransformer::SELF_LINK][JsonTransformer::LINKS_HREF] |
||
90 | ); |
||
91 | |||
92 | if ($key !== 'resource') { |
||
93 | $subnode->addAttribute('rel', $key); |
||
94 | } |
||
95 | } else { |
||
96 | $subnode = $xmlData->addChild($key); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | $this->arrayToXml($value, $subnode); |
||
101 | } else { |
||
102 | if ($key !== JsonTransformer::LINKS_HREF) { |
||
103 | if ($value === true || $value === false) { |
||
104 | $value = ($value) ? 'true' : 'false'; |
||
105 | } |
||
106 | |||
107 | $xmlData->addChild("$key", '<![CDATA['.html_entity_decode($value).']]>'); |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | } |
||
113 |