Complex classes like QueryBuilder often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use QueryBuilder, and based on these observations, apply Extract Interface, too.
1 | <?php namespace Arcanedev\LaravelNestedSet\Eloquent; |
||
19 | class QueryBuilder extends Builder |
||
20 | { |
||
21 | /* ------------------------------------------------------------------------------------------------ |
||
22 | | Properties |
||
23 | | ------------------------------------------------------------------------------------------------ |
||
24 | */ |
||
25 | /** |
||
26 | * @var \Arcanedev\LaravelNestedSet\Traits\NodeTrait|\Illuminate\Database\Eloquent\Model |
||
27 | */ |
||
28 | protected $model; |
||
29 | |||
30 | /* ------------------------------------------------------------------------------------------------ |
||
31 | | Main Functions |
||
32 | | ------------------------------------------------------------------------------------------------ |
||
33 | */ |
||
34 | /** |
||
35 | * Get node's `lft` and `rgt` values. |
||
36 | * |
||
37 | * @param mixed $id |
||
38 | * @param bool $required |
||
39 | * |
||
40 | * @return array |
||
41 | */ |
||
42 | 73 | public function getNodeData($id, $required = false) |
|
59 | |||
60 | /** |
||
61 | * Get plain node data. |
||
62 | * |
||
63 | * @param mixed $id |
||
64 | * @param bool $required |
||
65 | * |
||
66 | * @return array |
||
67 | */ |
||
68 | 45 | public function getPlainNodeData($id, $required = false) |
|
72 | |||
73 | /** |
||
74 | * Scope limits query to select just root node. |
||
75 | * |
||
76 | * @return self |
||
77 | */ |
||
78 | 20 | public function whereIsRoot() |
|
84 | |||
85 | /** |
||
86 | * Limit results to ancestors of specified node. |
||
87 | * |
||
88 | * @param mixed $id |
||
89 | * |
||
90 | * @return self |
||
91 | */ |
||
92 | 20 | public function whereAncestorOf($id) |
|
125 | |||
126 | /** |
||
127 | * Get ancestors of specified node. |
||
128 | * |
||
129 | * @param mixed $id |
||
130 | * @param array $columns |
||
131 | * |
||
132 | * @return self |
||
133 | */ |
||
134 | 12 | public function ancestorsOf($id, array $columns = ['*']) |
|
138 | |||
139 | /** |
||
140 | * Add node selection statement between specified range. |
||
141 | * |
||
142 | * @param array $values |
||
143 | * @param string $boolean |
||
144 | * @param bool $not |
||
145 | * |
||
146 | * @return self |
||
147 | */ |
||
148 | 43 | public function whereNodeBetween($values, $boolean = 'and', $not = false) |
|
154 | |||
155 | /** |
||
156 | * Add node selection statement between specified range joined with `or` operator. |
||
157 | * |
||
158 | * @param array $values |
||
159 | * |
||
160 | * @return self |
||
161 | */ |
||
162 | public function orWhereNodeBetween($values) |
||
166 | |||
167 | /** |
||
168 | * Add constraint statement to descendants of specified node. |
||
169 | * |
||
170 | * @param mixed $id |
||
171 | * @param string $boolean |
||
172 | * @param bool $not |
||
173 | * |
||
174 | * @return self |
||
175 | */ |
||
176 | 47 | public function whereDescendantOf($id, $boolean = 'and', $not = false) |
|
187 | |||
188 | /** |
||
189 | * @param mixed $id |
||
190 | * |
||
191 | * @return self |
||
192 | */ |
||
193 | public function whereNotDescendantOf($id) |
||
197 | |||
198 | /** |
||
199 | * @param mixed $id |
||
200 | * |
||
201 | * @return self |
||
202 | */ |
||
203 | 4 | public function orWhereDescendantOf($id) |
|
207 | |||
208 | /** |
||
209 | * @param mixed $id |
||
210 | * |
||
211 | * @return self |
||
212 | */ |
||
213 | public function orWhereNotDescendantOf($id) |
||
217 | |||
218 | /** |
||
219 | * Get descendants of specified node. |
||
220 | * |
||
221 | * @param mixed $id |
||
222 | * @param array $columns |
||
223 | * |
||
224 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection |
||
225 | */ |
||
226 | public function descendantsOf($id, array $columns = ['*']) |
||
235 | |||
236 | /** |
||
237 | * @param mixed $id |
||
238 | * @param string $operator |
||
239 | * @param string $boolean |
||
240 | * |
||
241 | * @return self |
||
242 | */ |
||
243 | protected function whereIsBeforeOrAfter($id, $operator, $boolean) |
||
268 | |||
269 | /** |
||
270 | * Constraint nodes to those that are after specified node. |
||
271 | * |
||
272 | * @param mixed $id |
||
273 | * @param string $boolean |
||
274 | * |
||
275 | * @return self |
||
276 | */ |
||
277 | public function whereIsAfter($id, $boolean = 'and') |
||
281 | |||
282 | /** |
||
283 | * Constraint nodes to those that are before specified node. |
||
284 | * |
||
285 | * @param mixed $id |
||
286 | * @param string $boolean |
||
287 | * |
||
288 | * @return self |
||
289 | */ |
||
290 | public function whereIsBefore($id, $boolean = 'and') |
||
294 | |||
295 | /** |
||
296 | * Include depth level into the result. |
||
297 | * |
||
298 | * @param string $as |
||
299 | * |
||
300 | * @return self |
||
301 | */ |
||
302 | 16 | public function withDepth($as = 'depth') |
|
323 | |||
324 | /** |
||
325 | * Get wrapped `lft` and `rgt` column names. |
||
326 | * |
||
327 | * @return array |
||
328 | */ |
||
329 | 48 | protected function wrappedColumns() |
|
338 | |||
339 | /** |
||
340 | * Get a wrapped table name. |
||
341 | * |
||
342 | * @return string |
||
343 | */ |
||
344 | 28 | protected function wrappedTable() |
|
348 | |||
349 | /** |
||
350 | * Wrap model's key name. |
||
351 | * |
||
352 | * @return string |
||
353 | */ |
||
354 | 12 | protected function wrappedKey() |
|
358 | |||
359 | /** |
||
360 | * Exclude root node from the result. |
||
361 | * |
||
362 | * @return self |
||
363 | */ |
||
364 | 8 | public function withoutRoot() |
|
370 | |||
371 | /** |
||
372 | * Order by node position. |
||
373 | * |
||
374 | * @param string $dir |
||
375 | * |
||
376 | * @return self |
||
377 | */ |
||
378 | 52 | public function defaultOrder($dir = 'asc') |
|
386 | |||
387 | /** |
||
388 | * Order by reversed node position. |
||
389 | * |
||
390 | * @return $this |
||
391 | */ |
||
392 | 4 | public function reversed() |
|
396 | |||
397 | /** |
||
398 | * Move a node to the new position. |
||
399 | * |
||
400 | * @param mixed $key |
||
401 | * @param int $position |
||
402 | * |
||
403 | * @return int |
||
404 | */ |
||
405 | 37 | public function moveNode($key, $position) |
|
445 | |||
446 | /** |
||
447 | * Make or remove gap in the tree. Negative height will remove gap. |
||
448 | * |
||
449 | * @param int $cut |
||
450 | * @param int $height |
||
451 | * |
||
452 | * @return int |
||
453 | */ |
||
454 | 47 | public function makeGap($cut, $height) |
|
465 | |||
466 | /** |
||
467 | * Get patch for columns. |
||
468 | * |
||
469 | * @param array $params |
||
470 | * |
||
471 | * @return array |
||
472 | */ |
||
473 | 80 | protected function patch(array $params) |
|
484 | |||
485 | /** |
||
486 | * Get patch for single column. |
||
487 | * |
||
488 | * @param string $col |
||
489 | * @param array $params |
||
490 | * |
||
491 | * @return string |
||
492 | */ |
||
493 | 80 | protected function columnPatch($col, array $params) |
|
522 | |||
523 | /** |
||
524 | * Get statistics of errors of the tree. |
||
525 | * |
||
526 | * @return array |
||
527 | */ |
||
528 | 12 | public function countErrors() |
|
548 | |||
549 | /** |
||
550 | * @return \Illuminate\Database\Query\Builder |
||
551 | */ |
||
552 | 12 | protected function getOddnessQuery() |
|
564 | |||
565 | /** |
||
566 | * @return \Illuminate\Database\Query\Builder |
||
567 | */ |
||
568 | 12 | protected function getDuplicatesQuery() |
|
588 | |||
589 | /** |
||
590 | * @return \Illuminate\Database\Query\Builder |
||
591 | */ |
||
592 | 12 | protected function getWrongParentQuery() |
|
618 | |||
619 | /** |
||
620 | * @return \Illuminate\Database\Query\Builder |
||
621 | */ |
||
622 | 12 | protected function getMissingParentQuery() |
|
646 | |||
647 | /** |
||
648 | * Get the number of total errors of the tree. |
||
649 | * |
||
650 | * @return int |
||
651 | */ |
||
652 | 8 | public function getTotalErrors() |
|
656 | |||
657 | /** |
||
658 | * Get whether the tree is broken. |
||
659 | * |
||
660 | * @return bool |
||
661 | */ |
||
662 | 8 | public function isBroken() |
|
666 | |||
667 | /** |
||
668 | * Fixes the tree based on parentage info. |
||
669 | * Nodes with invalid parent are saved as roots. |
||
670 | * |
||
671 | * @return int The number of fixed nodes |
||
672 | */ |
||
673 | 4 | public function fixTree() |
|
689 | |||
690 | /** |
||
691 | * Rebuild the tree based on raw data. |
||
692 | * If item data does not contain primary key, new node will be created. |
||
693 | * |
||
694 | * @param array $data |
||
695 | * @param bool $delete Whether to delete nodes that exists but not in the data array |
||
696 | * |
||
697 | * @return int |
||
698 | */ |
||
699 | 8 | public function rebuildTree(array $data, $delete = false) |
|
721 | |||
722 | /** |
||
723 | * @param array $dictionary |
||
724 | * @param array $data |
||
725 | * @param array $existing |
||
726 | * @param mixed $parentId |
||
727 | */ |
||
728 | 8 | protected function buildRebuildDictionary( |
|
764 | |||
765 | /** |
||
766 | * @param string|null $table |
||
767 | * |
||
768 | * @return self |
||
769 | */ |
||
770 | public function applyNestedSetScope($table = null) |
||
774 | |||
775 | /** |
||
776 | * Get the root node. |
||
777 | * |
||
778 | * @param array $columns |
||
779 | * |
||
780 | * @return self |
||
781 | */ |
||
782 | 16 | public function root(array $columns = ['*']) |
|
786 | } |
||
787 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.