Conditions | 10 |
Paths | 28 |
Total Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 15.8818 |
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 |
||
20 | 1 | protected function pStmts(array $nodes, bool $indent = true): string { |
|
21 | 1 | $result = ''; |
|
22 | 1 | $prevNode = null; |
|
23 | |||
24 | 1 | foreach ($nodes as $node) { |
|
25 | 1 | $comments = $node->getAttribute('comments', []); |
|
26 | 1 | if ($comments) { |
|
27 | $result .= "\n" . $this->pComments($comments); |
||
28 | if ($node instanceof Stmt\Nop) { |
||
29 | continue; |
||
30 | } |
||
31 | } |
||
32 | |||
33 | 1 | if ($prevNode && $prevNode->getLine() && $node->getLine()) { |
|
34 | $diff = $node->getLine()- $prevNode->getLine(); |
||
35 | if ($diff > 0) { |
||
36 | $result .= str_repeat("\n", $diff - 1); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | 1 | $result .= "\n" . $this->p($node) . ($node instanceof Expr ? ';' : ''); |
|
41 | 1 | $prevNode = $node; |
|
42 | } |
||
43 | |||
44 | 1 | if ($indent) { |
|
45 | return preg_replace('~\n(?!$)~', "\n ", $result); |
||
46 | } else { |
||
47 | 1 | return $result; |
|
48 | } |
||
49 | } |
||
50 | |||
55 |