| Conditions | 14 |
| Paths | 70 |
| Total Lines | 46 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 41 | protected function traverseArray(array $nodes) { |
||
| 42 | $doNodes = array(); |
||
| 43 | |||
| 44 | foreach ($nodes as $i => &$node) { |
||
| 45 | if (is_array($node)) { |
||
| 46 | $node = $this->traverseArray($node); |
||
| 47 | } elseif ($node instanceof Node) { |
||
| 48 | $traverseChildren = call_user_func($this->stopCondition, $node); |
||
| 49 | |||
| 50 | foreach ($this->visitors as $visitor) { |
||
| 51 | $return = $visitor->enterNode($node); |
||
| 52 | if (self::DONT_TRAVERSE_CHILDREN === $return) { |
||
| 53 | $traverseChildren = false; |
||
| 54 | } else if (null !== $return) { |
||
| 55 | $node = $return; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | if ($traverseChildren) { |
||
| 60 | $node = $this->traverseNode($node); |
||
| 61 | } |
||
| 62 | |||
| 63 | foreach ($this->visitors as $visitor) { |
||
| 64 | $return = $visitor->leaveNode($node); |
||
| 65 | |||
| 66 | if (self::REMOVE_NODE === $return) { |
||
| 67 | $doNodes[] = array($i, array()); |
||
| 68 | break; |
||
| 69 | } elseif (is_array($return)) { |
||
| 70 | $doNodes[] = array($i, $return); |
||
| 71 | break; |
||
| 72 | } elseif (null !== $return) { |
||
| 73 | $node = $return; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | if (!empty($doNodes)) { |
||
| 80 | while (list($i, $replace) = array_pop($doNodes)) { |
||
| 81 | array_splice($nodes, $i, 1, $replace); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | return $nodes; |
||
| 86 | } |
||
| 87 | |||
| 91 |