| Conditions | 12 |
| Paths | 12 |
| Total Lines | 43 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 24 |
| CRAP Score | 12 |
| 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 |
||
| 116 | 13 | public static function nodeToArray(DOMNode $node, Config $config): mixed |
|
| 117 | { |
||
| 118 | 13 | $result = [ |
|
| 119 | 13 | $config->attributesName => [], |
|
| 120 | 13 | $config->valueName => null, |
|
| 121 | 13 | $config->nodesName => [], |
|
| 122 | ]; |
||
| 123 | |||
| 124 | 13 | if ($node->hasAttributes()) { |
|
| 125 | /** @var \DOMAttr $attribute */ |
||
| 126 | 8 | foreach ($node->attributes ?? [] as $attribute) { |
|
| 127 | 8 | $result[$config->attributesName][$attribute->nodeName] = $config->autoCast |
|
| 128 | 1 | ? self::decodeValue($attribute->nodeValue) |
|
| 129 | 7 | : $attribute->nodeValue; |
|
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | 13 | if ($node->hasChildNodes()) { |
|
| 134 | /** @var \DOMNode $child */ |
||
| 135 | 11 | foreach ($node->childNodes ?? [] as $child) { |
|
| 136 | 11 | if (in_array($child->nodeType, [XML_TEXT_NODE, XML_CDATA_SECTION_NODE])) { |
|
| 137 | 11 | if (trim((string) $child->nodeValue) !== '') { |
|
| 138 | 11 | $result[$config->valueName] = $config->autoCast |
|
| 139 | 1 | ? self::decodeValue($child->nodeValue) |
|
| 140 | 10 | : $child->nodeValue; |
|
| 141 | } |
||
| 142 | |||
| 143 | 11 | continue; |
|
| 144 | } |
||
| 145 | |||
| 146 | 11 | $result[$config->nodesName][$child->nodeName][] = self::nodeToArray($child, $config); |
|
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | 13 | if ($config->fullResponse) { |
|
| 151 | 1 | return $result; |
|
| 152 | } |
||
| 153 | |||
| 154 | 12 | if (count($result[$config->nodesName]) === 0 && count($result[$config->attributesName]) === 0) { |
|
|
1 ignored issue
–
show
|
|||
| 155 | 10 | return $result[$config->valueName]; |
|
| 156 | } |
||
| 157 | |||
| 158 | 11 | return self::simplifyArray($result, $config, $node); |
|
| 159 | } |
||
| 192 |