Conditions | 12 |
Paths | 24 |
Total Lines | 41 |
Code Lines | 20 |
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 |
||
158 | private function adjustAllChildren(OutputBlock $block) |
||
159 | { |
||
160 | // flatten empty nested blocks |
||
161 | $children = []; |
||
162 | |||
163 | foreach ($block->children as $i => $child) { |
||
164 | if (empty($child->lines) && empty($child->children)) { |
||
165 | if (isset($block->children[$i + 1])) { |
||
166 | $block->children[$i + 1]->depth = $child->depth; |
||
167 | } |
||
168 | |||
169 | continue; |
||
170 | } |
||
171 | |||
172 | $children[] = $child; |
||
173 | } |
||
174 | |||
175 | $count = count($children); |
||
176 | |||
177 | for ($i = 0; $i < $count; $i++) { |
||
178 | $depth = $children[$i]->depth; |
||
179 | $j = $i + 1; |
||
180 | |||
181 | if (isset($children[$j]) && $depth < $children[$j]->depth) { |
||
182 | $childDepth = $children[$j]->depth; |
||
183 | |||
184 | for (; $j < $count; $j++) { |
||
185 | if ($depth < $children[$j]->depth && $childDepth >= $children[$j]->depth) { |
||
186 | $children[$j]->depth = $depth + 1; |
||
187 | } |
||
188 | } |
||
189 | } |
||
190 | } |
||
191 | |||
192 | $block->children = $children; |
||
193 | |||
194 | // make relative to parent |
||
195 | foreach ($block->children as $child) { |
||
196 | $this->adjustAllChildren($child); |
||
197 | |||
198 | $child->depth = $child->depth - $block->depth; |
||
199 | } |
||
202 |