Conditions | 18 |
Paths | 6 |
Total Lines | 101 |
Lines | 40 |
Ratio | 39.6 % |
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 |
||
179 | private function sortDescendantObjects( |
||
180 | HierarchicalInterface $parentObj, |
||
181 | array &$childObjects, |
||
182 | &$count, |
||
183 | $level, |
||
184 | array &$sortedObjects |
||
185 | ) { |
||
186 | $pageNum = $this->getPage(); |
||
187 | $perPage = $this->getNumPerPage(); |
||
188 | |||
189 | if ($perPage < 1) { |
||
190 | foreach ($childObjects[$parentObj->id()] as $object) { |
||
191 | View Code Duplication | if ($count === 0 && $object->hasMaster()) { |
|
192 | $myParents = []; |
||
193 | $myParent = $object->getMaster(); |
||
194 | while ($myParent) { |
||
195 | $myParents[] = $myParent; |
||
196 | |||
197 | if (!$myParent->hasMaster()) { |
||
198 | break; |
||
199 | } |
||
200 | |||
201 | $myParent = $myParent->getMaster(); |
||
202 | } |
||
203 | |||
204 | $numParents = count($myParents); |
||
205 | while ($myParent = array_pop($myParents)) { |
||
206 | $myParent->level = ($level - $numParents); |
||
207 | $sortedObjects[$myParent->id()] = $myParent; |
||
208 | $numParents--; |
||
209 | } |
||
210 | } |
||
211 | |||
212 | $object->level = $level; |
||
213 | $sortedObjects[$object->id()] = $object; |
||
214 | |||
215 | $count++; |
||
216 | |||
217 | if (isset($childObjects[$object->id()])) { |
||
218 | $this->sortDescendantObjects( |
||
219 | $object, |
||
220 | $childObjects, |
||
221 | $count, |
||
222 | ($level + 1), |
||
223 | $sortedObjects |
||
224 | ); |
||
225 | } |
||
226 | } |
||
227 | } else { |
||
228 | $start = (( $pageNum - 1 ) * $perPage); |
||
229 | $end = ($start + $perPage); |
||
230 | |||
231 | foreach ($childObjects[$parentObj->id()] as $object) { |
||
232 | if ($count >= $end) { |
||
233 | break; |
||
234 | } |
||
235 | |||
236 | // If the page starts in a subtree, print the parents. |
||
237 | View Code Duplication | if ($count === $start && $object->hasMaster()) { |
|
238 | $myParents = []; |
||
239 | $myParent = $object->getMaster(); |
||
240 | while ($myParent) { |
||
241 | $myParents[] = $myParent; |
||
242 | |||
243 | if (!$myParent->hasMaster()) { |
||
244 | break; |
||
245 | } |
||
246 | |||
247 | $myParent = $myParent->getMaster(); |
||
248 | } |
||
249 | |||
250 | $numParents = count($myParents); |
||
251 | while ($myParent = array_pop($myParents)) { |
||
252 | $myParent->level = ($level - $numParents); |
||
253 | $sortedObjects[$myParent->id()] = $myParent; |
||
254 | $numParents--; |
||
255 | } |
||
256 | } |
||
257 | |||
258 | if ($count >= $start) { |
||
259 | $object->level = $level; |
||
260 | $sortedObjects[$object->id()] = $object; |
||
261 | } |
||
262 | |||
263 | $count++; |
||
264 | |||
265 | if (isset($childObjects[$object->id()])) { |
||
266 | $this->sortDescendantObjects( |
||
267 | $object, |
||
268 | $childObjects, |
||
269 | $count, |
||
270 | ($level + 1), |
||
271 | $sortedObjects |
||
272 | ); |
||
273 | } |
||
274 | } |
||
275 | } |
||
276 | |||
277 | // Required in order to keep track of orphans |
||
278 | unset($childObjects[$parentObj->id()]); |
||
279 | } |
||
280 | |||
359 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.