Conditions | 10 |
Paths | 7 |
Total Lines | 20 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
44 | public static function removeTextNodesRecursively(Twig_Node $node, Twig_Parser $parser) |
||
45 | { |
||
46 | foreach ($node->getIterator() as $key => $subNode) { |
||
47 | if ($subNode instanceof Twig_Node_Text) { |
||
48 | // Never delete a block body |
||
49 | if ($key === 'body' && $node instanceof Twig_Node_Block) { |
||
50 | continue; |
||
51 | } |
||
52 | |||
53 | $node->removeNode($key); |
||
54 | } elseif ($subNode instanceof Twig_Node_BlockReference) { |
||
55 | self::removeTextNodesRecursively($parser->getBlock($subNode->getAttribute('name')), $parser); |
||
56 | } elseif ($subNode instanceof Twig_Node && $subNode->count() > 0) { |
||
57 | if ($subNode instanceof XlsNode && $subNode->canContainText()) { |
||
58 | continue; |
||
59 | } |
||
60 | self::removeTextNodesRecursively($subNode, $parser); |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | |||
112 |