Conditions | 12 |
Paths | 38 |
Total Lines | 48 |
Code Lines | 38 |
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 |
||
81 | public function buildNodeCollectionFromMultiLine(array $lines): NodeCollection |
||
82 | { |
||
83 | $nodeCollection = new NodeCollection(); |
||
84 | |||
85 | $assignments = []; |
||
86 | $prefixes = []; |
||
87 | $level = 0; |
||
88 | $inMultiLineValue = false; |
||
89 | $multiLineValue = ''; |
||
90 | $leftValue = ''; |
||
91 | foreach ($lines as $line) { |
||
92 | if (!$inMultiLineValue) { |
||
93 | $line = trim($line); |
||
94 | } |
||
95 | if ($inMultiLineValue) { |
||
96 | if (substr(trim($line), -1, 1) === ')') { |
||
97 | $lineString = (empty($prefixes)) |
||
98 | ? $leftValue . '(' . PHP_EOL . $multiLineValue . ')' |
||
99 | : implode('.', $prefixes) . '.' . $leftValue . '(' . PHP_EOL . $multiLineValue . ')'; |
||
100 | $assignments[] = new Assignment($lineString); |
||
101 | $multiLineValue = ''; |
||
102 | $leftValue = ''; |
||
103 | $inMultiLineValue = false; |
||
104 | } else { |
||
105 | $multiLineValue .= $line; |
||
106 | } |
||
107 | } elseif (substr(trim($line), -1, 1) === '{') { |
||
108 | $prefixes[$level] = trim(rtrim($line, '{')); |
||
109 | $level++; |
||
110 | } elseif (substr(trim($line), -1, 1) === '}') { |
||
111 | $level--; |
||
112 | unset($prefixes[$level]); |
||
113 | } elseif (substr(trim($line), -1, 1) === '(') { |
||
114 | $leftValue = trim(rtrim(trim($line), '(')); |
||
115 | $inMultiLineValue = true; |
||
116 | } elseif (trim($line) !== '') { |
||
117 | $lineString = (empty($prefixes)) |
||
118 | ? trim(rtrim($line, '{')) |
||
119 | : implode('.', $prefixes) . '.' . trim(rtrim($line, '{')); |
||
120 | $assignments[] = new Assignment($lineString); |
||
121 | } |
||
122 | } |
||
123 | |||
124 | foreach ($assignments as $assignment) { |
||
125 | $nodeCollection = $this->mergeNodeCollections($nodeCollection, $this->buildNodeCollectionFromAssignment($assignment)); |
||
126 | } |
||
127 | |||
128 | return $nodeCollection; |
||
129 | } |
||
157 |