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