Conditions | 10 |
Paths | 3 |
Total Lines | 30 |
Code Lines | 22 |
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 |
||
19 | public function getFinalString(NodeList $list):string |
||
20 | { |
||
21 | $result = ''; |
||
22 | if ($list->count()) { |
||
23 | if ($this->identifier !== '+') { |
||
24 | self::litteralStripLeading($list); |
||
25 | self::litteralStripTrailing($list); |
||
26 | } |
||
27 | $first = $list->shift(); |
||
28 | $refIndent = $first->indent ?? 0; |
||
29 | $refSeparator = ' '; |
||
30 | $result = substr($first->raw, $first->indent); |
||
31 | foreach ($list as $child) { |
||
32 | if($child->indent > $refIndent || ($child instanceof NodeBlank)) { |
||
33 | $separator = "\n"; |
||
34 | } else { |
||
35 | $separator = !empty($result) && $result[-1] === "\n" ? '' : $refSeparator; |
||
36 | } |
||
37 | $val = ''; |
||
38 | if ($child->value instanceof NodeList) { |
||
39 | $val = "\n".$this->getFinalString($child->value); |
||
40 | } else { |
||
41 | if ($child instanceof NodeScalar) { |
||
42 | $val = $child->build(); |
||
43 | } |
||
44 | } |
||
45 | $result .= $separator .$val; |
||
46 | } |
||
47 | } |
||
48 | return $result; |
||
49 | } |
||
50 | } |