| Conditions | 15 |
| Paths | 18 |
| Total Lines | 49 |
| Code Lines | 24 |
| 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 |
||
| 70 | protected function crawl($elements, \DOMNode $parentNode = null) |
||
| 71 | { |
||
| 72 | $branch = []; |
||
| 73 | |||
| 74 | foreach ($elements as $index => $items) { |
||
| 75 | |||
| 76 | if ($index == "_mapping") { |
||
| 77 | continue; |
||
| 78 | } |
||
| 79 | |||
| 80 | if (array_key_exists(0, $items)) { |
||
| 81 | $items = $items[0]; |
||
| 82 | } |
||
| 83 | |||
| 84 | $mapping = $items["_mapping"]; |
||
| 85 | |||
| 86 | if (is_array($items) && sizeof($items) - (array_key_exists("_mapping", $items)? 1 : 0) > 0) { |
||
| 87 | |||
| 88 | if (empty($parentNode) || $parentNode instanceof \DOMElement) { |
||
| 89 | |||
| 90 | $nodes = $this->xpath->query($mapping, $parentNode); |
||
| 91 | |||
| 92 | if ($nodes->length == 1) { |
||
| 93 | $branch[$index] = $this->crawl($items, $nodes->item(0)); |
||
| 94 | } else { |
||
| 95 | foreach ($nodes as $node) { |
||
| 96 | $branch[$index][] = $this->crawl($items, $node); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | } else { |
||
| 102 | if (empty($parentNode) || $parentNode instanceof \DOMElement) { |
||
| 103 | |||
| 104 | $nodes = $this->xpath->query($mapping, $parentNode); |
||
| 105 | |||
| 106 | if ($nodes->length == 1) { |
||
| 107 | $branch[$index] = trim($nodes->item(0)->nodeValue); |
||
| 108 | } else { |
||
| 109 | foreach ($nodes as $k => $node) { |
||
| 110 | $branch[$index][] = trim($node->nodeValue); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | return $branch; |
||
| 119 | } |
||
| 121 |