| Conditions | 7 |
| Paths | 5 |
| Total Lines | 57 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 42 | protected function parse_html_tree(array $tree) |
||
| 43 | { |
||
| 44 | $nodes = []; |
||
| 45 | |||
| 46 | foreach ($tree as $node) |
||
| 47 | { |
||
| 48 | if (is_array($node)) |
||
| 49 | { |
||
| 50 | $children = []; |
||
| 51 | |||
| 52 | if (isset($node['children'])) |
||
| 53 | { |
||
| 54 | $children = $this->parse_html_tree($node['children']); |
||
| 55 | } |
||
| 56 | |||
| 57 | $nodes[] = new ControlNode($node['name'], $node['args'], $children); |
||
| 58 | } |
||
| 59 | else |
||
| 60 | { |
||
| 61 | # |
||
| 62 | # we don't resolve comments, unless they are Internet Explorer comments e.g. <!--[ |
||
| 63 | # |
||
| 64 | |||
| 65 | $parts = preg_split('#(<!--(?!\[).+-->)#sU', $node, -1, PREG_SPLIT_DELIM_CAPTURE); |
||
| 66 | |||
| 67 | if (count($parts) == 1) |
||
| 68 | { |
||
| 69 | $children = $this->parse_html_node($node); |
||
| 70 | |||
| 71 | $nodes = array_merge($nodes, $children); |
||
| 72 | } |
||
| 73 | else |
||
| 74 | { |
||
| 75 | # |
||
| 76 | # The comments, which are on odd position, are kept intact. The text, which is |
||
| 77 | # on even position is resolved. |
||
| 78 | # |
||
| 79 | |||
| 80 | foreach ($parts as $i => $part) |
||
| 81 | { |
||
| 82 | if ($i % 2) |
||
| 83 | { |
||
| 84 | $nodes[] = new TextNode($part); |
||
| 85 | } |
||
| 86 | else |
||
| 87 | { |
||
| 88 | $children = $this->parse_html_node($part); |
||
| 89 | |||
| 90 | $nodes = array_merge($nodes, $children); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | return $nodes; |
||
| 98 | } |
||
| 99 | |||
| 170 |