Conditions | 10 |
Paths | 7 |
Total Lines | 20 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
25 | protected function removeTextNodesRecursively(Twig_Node $node) |
||
26 | { |
||
27 | foreach ($node->getIterator() as $key => $subNode) { |
||
28 | if ($subNode instanceof Twig_Node_Text) { |
||
29 | // Never delete a block body |
||
30 | if ($key === 'body' && $node instanceof Twig_Node_Block) { |
||
31 | continue; |
||
32 | } |
||
33 | |||
34 | $node->removeNode($key); |
||
35 | } elseif ($subNode instanceof Twig_Node_BlockReference) { |
||
36 | $this->removeTextNodesRecursively($this->parser->getBlock($subNode->getAttribute('name'))); |
||
|
|||
37 | } elseif ($subNode instanceof Twig_Node && $subNode->count() > 0) { |
||
38 | if ($subNode instanceof XlsNode && $subNode->canContainText()) { |
||
39 | continue; |
||
40 | } |
||
41 | $this->removeTextNodesRecursively($subNode); |
||
42 | } |
||
43 | } |
||
44 | } |
||
45 | } |
||
46 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: