| Conditions | 14 |
| Paths | 70 |
| Total Lines | 46 |
| 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 |
||
| 50 | public function traverseArray(array $nodes, array $visitors) { |
||
| 51 | $doNodes = array(); |
||
| 52 | |||
| 53 | foreach ($nodes as $i => &$node) { |
||
| 54 | if (is_array($node)) { |
||
| 55 | $node = $this->traverseArray($node, $visitors); |
||
| 56 | } elseif ($node instanceof Node) { |
||
| 57 | $traverseChildren = call_user_func($this->stopCondition, $node); |
||
| 58 | |||
| 59 | foreach ($visitors as $visitor) { |
||
| 60 | $return = $visitor->enterNode($node); |
||
| 61 | if (Mother::DONT_TRAVERSE_CHILDREN === $return) { |
||
| 62 | $traverseChildren = false; |
||
| 63 | } else if (null !== $return) { |
||
| 64 | $node = $return; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if ($traverseChildren) { |
||
| 69 | $node = $this->traverser->traverseNode($node); |
||
| 70 | } |
||
| 71 | |||
| 72 | foreach ($visitors as $visitor) { |
||
| 73 | $return = $visitor->leaveNode($node); |
||
| 74 | |||
| 75 | if (Mother::REMOVE_NODE === $return) { |
||
| 76 | $doNodes[] = array($i, array()); |
||
| 77 | break; |
||
| 78 | } elseif (is_array($return)) { |
||
| 79 | $doNodes[] = array($i, $return); |
||
| 80 | break; |
||
| 81 | } elseif (null !== $return) { |
||
| 82 | $node = $return; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | if (!empty($doNodes)) { |
||
| 89 | while (list($i, $replace) = array_pop($doNodes)) { |
||
| 90 | array_splice($nodes, $i, 1, $replace); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | return $nodes; |
||
| 95 | } |
||
| 96 | } |
||
| 142 | } |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.