Complex classes like NodeTrait 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 NodeTrait, and based on these observations, apply Extract Interface, too.
1 | <?php namespace Arcanedev\LaravelNestedSet\Traits; |
||
29 | trait NodeTrait |
||
30 | { |
||
31 | /* ------------------------------------------------------------------------------------------------ |
||
32 | | Properties |
||
33 | | ------------------------------------------------------------------------------------------------ |
||
34 | */ |
||
35 | /** |
||
36 | * Pending operation. |
||
37 | * |
||
38 | * @var array|null |
||
39 | */ |
||
40 | protected $pending; |
||
41 | |||
42 | /** |
||
43 | * Whether the node has moved since last save. |
||
44 | * |
||
45 | * @var bool |
||
46 | */ |
||
47 | protected $moved = false; |
||
48 | |||
49 | /** |
||
50 | * @var \Carbon\Carbon |
||
51 | */ |
||
52 | public static $deletedAt; |
||
53 | |||
54 | /** |
||
55 | * Keep track of the number of performed operations. |
||
56 | * |
||
57 | * @var int |
||
58 | */ |
||
59 | public static $actionsPerformed = 0; |
||
60 | |||
61 | /* ------------------------------------------------------------------------------------------------ |
||
62 | | Boot Function |
||
63 | | ------------------------------------------------------------------------------------------------ |
||
64 | */ |
||
65 | /** |
||
66 | * Sign on model events. |
||
67 | */ |
||
68 | 280 | public static function bootNodeTrait() |
|
113 | |||
114 | /* ------------------------------------------------------------------------------------------------ |
||
115 | | Eloquent Functions |
||
116 | | ------------------------------------------------------------------------------------------------ |
||
117 | */ |
||
118 | /** |
||
119 | * Get the database connection for the model. |
||
120 | * |
||
121 | * @return \Illuminate\Database\Connection |
||
122 | */ |
||
123 | abstract public function getConnection(); |
||
124 | |||
125 | /** |
||
126 | * Get the table associated with the model. |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | abstract public function getTable(); |
||
131 | |||
132 | /** |
||
133 | * Get the value of the model's primary key. |
||
134 | * |
||
135 | * @return mixed |
||
136 | */ |
||
137 | abstract public function getKey(); |
||
138 | |||
139 | /** |
||
140 | * Get the primary key for the model. |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | abstract public function getKeyName(); |
||
145 | |||
146 | /** |
||
147 | * Get a plain attribute (not a relationship). |
||
148 | * |
||
149 | * @param string $key |
||
150 | * |
||
151 | * @return mixed |
||
152 | */ |
||
153 | abstract public function getAttributeValue($key); |
||
154 | |||
155 | /** |
||
156 | * Set the array of model attributes. No checking is done. |
||
157 | * |
||
158 | * @param array $attributes |
||
159 | * @param bool $sync |
||
160 | * |
||
161 | * @return self |
||
162 | */ |
||
163 | abstract public function setRawAttributes(array $attributes, $sync = false); |
||
164 | |||
165 | /** |
||
166 | * Set the specific relationship in the model. |
||
167 | * |
||
168 | * @param string $relation |
||
169 | * @param mixed $value |
||
170 | * |
||
171 | * @return self |
||
172 | */ |
||
173 | abstract public function setRelation($relation, $value); |
||
174 | |||
175 | /** |
||
176 | * Get a relationship. |
||
177 | * |
||
178 | * @param string $key |
||
179 | * |
||
180 | * @return mixed |
||
181 | */ |
||
182 | abstract public function getRelationValue($key); |
||
183 | |||
184 | /** |
||
185 | * Create a new instance of the given model. |
||
186 | * |
||
187 | * @param array $attributes |
||
188 | * @param bool $exists |
||
189 | * |
||
190 | * @return self |
||
191 | */ |
||
192 | abstract public function newInstance($attributes = [], $exists = false); |
||
193 | |||
194 | /** |
||
195 | * Determine if the model or given attribute(s) have been modified. |
||
196 | * |
||
197 | * @param array|string|null $attributes |
||
198 | * |
||
199 | * @return bool |
||
200 | */ |
||
201 | abstract public function isDirty($attributes = null); |
||
202 | |||
203 | /** |
||
204 | * Fill the model with an array of attributes. |
||
205 | * |
||
206 | * @param array $attributes |
||
207 | * |
||
208 | * @return self |
||
209 | * |
||
210 | * @throws \Illuminate\Database\Eloquent\MassAssignmentException |
||
211 | */ |
||
212 | abstract public function fill(array $attributes); |
||
213 | |||
214 | /** |
||
215 | * Save the model to the database. |
||
216 | * |
||
217 | * @param array $options |
||
218 | * |
||
219 | * @return bool |
||
220 | */ |
||
221 | abstract public function save(array $options = []); |
||
222 | |||
223 | /** |
||
224 | * Get a new query builder for the model's table. |
||
225 | * |
||
226 | * @return \Illuminate\Database\Eloquent\Builder |
||
227 | */ |
||
228 | abstract public function newQuery(); |
||
229 | |||
230 | /* ------------------------------------------------------------------------------------------------ |
||
231 | | Relationships |
||
232 | | ------------------------------------------------------------------------------------------------ |
||
233 | */ |
||
234 | /** |
||
235 | * Relation to the parent. |
||
236 | * |
||
237 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
238 | */ |
||
239 | 16 | public function parent() |
|
244 | |||
245 | /** |
||
246 | * Relation to children. |
||
247 | * |
||
248 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
249 | */ |
||
250 | 16 | public function children() |
|
255 | |||
256 | /** |
||
257 | * Get query for descendants of the node. |
||
258 | * |
||
259 | * @return \Arcanedev\LaravelNestedSet\Eloquent\DescendantsRelation |
||
260 | */ |
||
261 | 44 | public function descendants() |
|
265 | |||
266 | /** |
||
267 | * Get query for siblings of the node. |
||
268 | * |
||
269 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
270 | */ |
||
271 | 8 | public function siblings() |
|
277 | |||
278 | /* ------------------------------------------------------------------------------------------------ |
||
279 | | Getters & Setters |
||
280 | | ------------------------------------------------------------------------------------------------ |
||
281 | */ |
||
282 | /** |
||
283 | * Get the lft key name. |
||
284 | * |
||
285 | * @return string |
||
286 | */ |
||
287 | 248 | public function getLftName() |
|
291 | |||
292 | /** |
||
293 | * Get the rgt key name. |
||
294 | * |
||
295 | * @return string |
||
296 | */ |
||
297 | 216 | public function getRgtName() |
|
301 | |||
302 | /** |
||
303 | * Get the parent id key name. |
||
304 | * |
||
305 | * @return string |
||
306 | */ |
||
307 | 164 | public function getParentIdName() |
|
311 | |||
312 | /** |
||
313 | * Get the value of the model's lft key. |
||
314 | * |
||
315 | * @return int |
||
316 | */ |
||
317 | 180 | public function getLft() |
|
321 | |||
322 | /** |
||
323 | * Set the value of the model's lft key. |
||
324 | * |
||
325 | * @param int $value |
||
326 | * |
||
327 | * @return self |
||
328 | */ |
||
329 | 92 | public function setLft($value) |
|
335 | |||
336 | /** |
||
337 | * Get the value of the model's rgt key. |
||
338 | * |
||
339 | * @return int |
||
340 | */ |
||
341 | 120 | public function getRgt() |
|
345 | |||
346 | /** |
||
347 | * Set the value of the model's rgt key. |
||
348 | * |
||
349 | * @param int $value |
||
350 | * |
||
351 | * @return self |
||
352 | */ |
||
353 | 92 | public function setRgt($value) |
|
359 | |||
360 | /** |
||
361 | * Get the value of the model's parent id key. |
||
362 | * |
||
363 | * @return int |
||
364 | */ |
||
365 | 96 | public function getParentId() |
|
369 | |||
370 | /** |
||
371 | * Set the value of the model's parent id key. |
||
372 | * |
||
373 | * @param int $value |
||
374 | * |
||
375 | * @return self |
||
376 | */ |
||
377 | 64 | public function setParentId($value) |
|
383 | |||
384 | /** |
||
385 | * Apply parent model. |
||
386 | * |
||
387 | * @param \Illuminate\Database\Eloquent\Model|null $value |
||
388 | * |
||
389 | * @return self |
||
390 | */ |
||
391 | 56 | protected function setParent($value) |
|
398 | |||
399 | /** |
||
400 | * Set the value of model's parent id key. |
||
401 | * |
||
402 | * Behind the scenes node is appended to found parent node. |
||
403 | * |
||
404 | * @param int $value |
||
405 | * |
||
406 | * @throws Exception If parent node doesn't exists |
||
407 | */ |
||
408 | 12 | public function setParentIdAttribute($value) |
|
421 | |||
422 | /** |
||
423 | * Get the boundaries. |
||
424 | * |
||
425 | * @return array |
||
426 | */ |
||
427 | 44 | public function getBounds() |
|
431 | |||
432 | /** |
||
433 | * Set the lft and rgt boundaries to null. |
||
434 | * |
||
435 | * @return self |
||
436 | */ |
||
437 | 68 | protected function dirtyBounds() |
|
441 | |||
442 | /** |
||
443 | * Returns node that is next to current node without constraining to siblings. |
||
444 | * This can be either a next sibling or a next sibling of the parent node. |
||
445 | * |
||
446 | * @param array $columns |
||
447 | * |
||
448 | * @return self |
||
449 | */ |
||
450 | public function getNextNode(array $columns = ['*']) |
||
454 | |||
455 | /** |
||
456 | * Returns node that is before current node without constraining to siblings. |
||
457 | * This can be either a prev sibling or parent node. |
||
458 | * |
||
459 | * @param array $columns |
||
460 | * |
||
461 | * @return self |
||
462 | */ |
||
463 | 4 | public function getPrevNode(array $columns = ['*']) |
|
467 | |||
468 | /** |
||
469 | * Get the ancestors nodes. |
||
470 | * |
||
471 | * @param array $columns |
||
472 | * |
||
473 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection |
||
474 | */ |
||
475 | 8 | public function getAncestors(array $columns = ['*']) |
|
481 | |||
482 | /** |
||
483 | * Get the descendants nodes. |
||
484 | * |
||
485 | * @param array $columns |
||
486 | * |
||
487 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection|self[] |
||
488 | */ |
||
489 | 12 | public function getDescendants(array $columns = ['*']) |
|
493 | |||
494 | /** |
||
495 | * Get the siblings nodes. |
||
496 | * |
||
497 | * @param array $columns |
||
498 | * |
||
499 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection|self[] |
||
500 | */ |
||
501 | 8 | public function getSiblings(array $columns = ['*']) |
|
505 | |||
506 | /** |
||
507 | * Get the next siblings nodes. |
||
508 | * |
||
509 | * @param array $columns |
||
510 | * |
||
511 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection|self[] |
||
512 | */ |
||
513 | 8 | public function getNextSiblings(array $columns = ['*']) |
|
517 | |||
518 | /** |
||
519 | * Get the previous siblings nodes. |
||
520 | * |
||
521 | * @param array $columns |
||
522 | * |
||
523 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection|self[] |
||
524 | */ |
||
525 | 8 | public function getPrevSiblings(array $columns = ['*']) |
|
529 | |||
530 | /** |
||
531 | * Get the next sibling node. |
||
532 | * |
||
533 | * @param array $columns |
||
534 | * |
||
535 | * @return self |
||
536 | */ |
||
537 | 4 | public function getNextSibling(array $columns = ['*']) |
|
541 | |||
542 | /** |
||
543 | * Get the previous sibling node. |
||
544 | * |
||
545 | * @param array $columns |
||
546 | * |
||
547 | * @return self |
||
548 | */ |
||
549 | 4 | public function getPrevSibling(array $columns = ['*']) |
|
553 | |||
554 | /** |
||
555 | * Get node height (rgt - lft + 1). |
||
556 | * |
||
557 | * @return int |
||
558 | */ |
||
559 | 36 | public function getNodeHeight() |
|
565 | |||
566 | /** |
||
567 | * Get number of descendant nodes. |
||
568 | * |
||
569 | * @return int |
||
570 | */ |
||
571 | 4 | public function getDescendantCount() |
|
575 | |||
576 | /** |
||
577 | * Get an attribute array of all arrayable relations. |
||
578 | * |
||
579 | * @return array |
||
580 | */ |
||
581 | protected function getArrayableRelations() |
||
589 | |||
590 | /** |
||
591 | * Set an action. |
||
592 | * |
||
593 | * @param string $action |
||
594 | * |
||
595 | * @return self |
||
596 | */ |
||
597 | 116 | protected function setNodeAction($action) |
|
604 | |||
605 | /** |
||
606 | * @return bool |
||
607 | */ |
||
608 | 8 | protected function actionRaw() |
|
612 | |||
613 | /** |
||
614 | * Call pending action. |
||
615 | * |
||
616 | * @return null|false |
||
617 | */ |
||
618 | 96 | protected function callPendingAction() |
|
634 | |||
635 | /* ------------------------------------------------------------------------------------------------ |
||
636 | | Other Functions |
||
637 | | ------------------------------------------------------------------------------------------------ |
||
638 | */ |
||
639 | /** |
||
640 | * Make a root node. |
||
641 | */ |
||
642 | 32 | protected function actionRoot() |
|
662 | |||
663 | /** |
||
664 | * Get the lower bound. |
||
665 | * |
||
666 | * @return int |
||
667 | */ |
||
668 | 32 | protected function getLowerBound() |
|
672 | |||
673 | /** |
||
674 | * Append or prepend a node to the parent. |
||
675 | * |
||
676 | * @param self $parent |
||
677 | * @param bool $prepend |
||
678 | * |
||
679 | * @return bool |
||
680 | */ |
||
681 | 32 | protected function actionAppendOrPrepend(self $parent, $prepend = false) |
|
695 | |||
696 | /** |
||
697 | * Insert node before or after another node. |
||
698 | * |
||
699 | * @param self $node |
||
700 | * @param bool $after |
||
701 | * |
||
702 | * @return bool |
||
703 | */ |
||
704 | 28 | protected function actionBeforeOrAfter(self $node, $after = false) |
|
710 | |||
711 | /** |
||
712 | * Refresh node's crucial attributes. |
||
713 | */ |
||
714 | 88 | public function refreshNode() |
|
723 | |||
724 | /** |
||
725 | * Get query for siblings after the node. |
||
726 | * |
||
727 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
728 | */ |
||
729 | 24 | public function nextSiblings() |
|
734 | |||
735 | /** |
||
736 | * Get query for siblings before the node. |
||
737 | * |
||
738 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
739 | */ |
||
740 | 16 | public function prevSiblings() |
|
745 | |||
746 | /** |
||
747 | * Get query for nodes after current node. |
||
748 | * |
||
749 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
750 | */ |
||
751 | 28 | public function nextNodes() |
|
756 | |||
757 | /** |
||
758 | * Get query for nodes before current node in reversed order. |
||
759 | * |
||
760 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
761 | */ |
||
762 | 20 | public function prevNodes() |
|
767 | |||
768 | /** |
||
769 | * Get query for ancestors to the node not including the node itself. |
||
770 | * |
||
771 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
772 | */ |
||
773 | 4 | public function ancestors() |
|
778 | |||
779 | /** |
||
780 | * Make this node a root node. |
||
781 | * |
||
782 | * @return self |
||
783 | */ |
||
784 | 48 | public function makeRoot() |
|
788 | |||
789 | /** |
||
790 | * Save node as root. |
||
791 | * |
||
792 | * @return bool |
||
793 | */ |
||
794 | 8 | public function saveAsRoot() |
|
802 | |||
803 | /** |
||
804 | * Append and save a node. |
||
805 | * |
||
806 | * @param self $node |
||
807 | * |
||
808 | * @return bool |
||
809 | */ |
||
810 | 16 | public function appendNode(self $node) |
|
814 | |||
815 | /** |
||
816 | * Prepend and save a node. |
||
817 | * |
||
818 | * @param self $node |
||
819 | * |
||
820 | * @return bool |
||
821 | */ |
||
822 | 4 | public function prependNode(self $node) |
|
826 | |||
827 | /** |
||
828 | * Append a node to the new parent. |
||
829 | * |
||
830 | * @param self $parent |
||
831 | * |
||
832 | * @return self |
||
833 | */ |
||
834 | 40 | public function appendToNode(self $parent) |
|
838 | |||
839 | /** |
||
840 | * Prepend a node to the new parent. |
||
841 | * |
||
842 | * @param self $parent |
||
843 | * |
||
844 | * @return self |
||
845 | */ |
||
846 | 4 | public function prependToNode(self $parent) |
|
850 | |||
851 | /** |
||
852 | * @param self $parent |
||
853 | * @param bool $prepend |
||
854 | * |
||
855 | * @return self |
||
856 | */ |
||
857 | 44 | public function appendOrPrependTo(self $parent, $prepend = false) |
|
866 | |||
867 | /** |
||
868 | * Insert self after a node. |
||
869 | * |
||
870 | * @param self $node |
||
871 | * |
||
872 | * @return self |
||
873 | */ |
||
874 | 28 | public function afterNode(self $node) |
|
878 | |||
879 | /** |
||
880 | * Insert self before node. |
||
881 | * |
||
882 | * @param self $node |
||
883 | * |
||
884 | * @return self |
||
885 | */ |
||
886 | 8 | public function beforeNode(self $node) |
|
890 | |||
891 | /** |
||
892 | * @param self $node |
||
893 | * @param bool $after |
||
894 | * |
||
895 | * @return self |
||
896 | */ |
||
897 | 36 | public function beforeOrAfterNode(self $node, $after = false) |
|
909 | |||
910 | /** |
||
911 | * Insert self after a node and save. |
||
912 | * |
||
913 | * @param self $node |
||
914 | * |
||
915 | * @return bool |
||
916 | */ |
||
917 | 16 | public function insertAfterNode(self $node) |
|
921 | |||
922 | /** |
||
923 | * Insert self before a node and save. |
||
924 | * |
||
925 | * @param self $node |
||
926 | * |
||
927 | * @return bool |
||
928 | */ |
||
929 | 4 | public function insertBeforeNode(self $node) |
|
938 | |||
939 | /** |
||
940 | * @param int $lft |
||
941 | * @param int $rgt |
||
942 | * @param int $parentId |
||
943 | * |
||
944 | * @return self |
||
945 | */ |
||
946 | 8 | public function rawNode($lft, $rgt, $parentId) |
|
952 | |||
953 | /** |
||
954 | * Move node up given amount of positions. |
||
955 | * |
||
956 | * @param int $amount |
||
957 | * |
||
958 | * @return bool |
||
959 | */ |
||
960 | 4 | public function up($amount = 1) |
|
971 | |||
972 | /** |
||
973 | * Move node down given amount of positions. |
||
974 | * |
||
975 | * @param int $amount |
||
976 | * |
||
977 | * @return bool |
||
978 | */ |
||
979 | 16 | public function down($amount = 1) |
|
990 | |||
991 | /** |
||
992 | * Insert node at specific position. |
||
993 | * |
||
994 | * @param int $position |
||
995 | * |
||
996 | * @return bool |
||
997 | */ |
||
998 | 68 | protected function insertAt($position) |
|
1008 | |||
1009 | /** |
||
1010 | * Move a node to the new position. |
||
1011 | * |
||
1012 | * @param int $position |
||
1013 | * |
||
1014 | * @return int |
||
1015 | */ |
||
1016 | 40 | protected function moveNode($position) |
|
1025 | |||
1026 | /** |
||
1027 | * Insert new node at specified position. |
||
1028 | * |
||
1029 | * @param int $position |
||
1030 | * |
||
1031 | * @return bool |
||
1032 | */ |
||
1033 | 32 | protected function insertNode($position) |
|
1044 | |||
1045 | /** |
||
1046 | * Update the tree when the node is removed physically. |
||
1047 | */ |
||
1048 | 20 | protected function deleteDescendants() |
|
1070 | |||
1071 | /** |
||
1072 | * Restore the descendants. |
||
1073 | * |
||
1074 | * @param mixed $deletedAt |
||
1075 | */ |
||
1076 | 4 | protected function restoreDescendants($deletedAt) |
|
1083 | |||
1084 | /** |
||
1085 | * Create a new Eloquent query builder for the model. |
||
1086 | * |
||
1087 | * @param \Illuminate\Database\Query\Builder $query |
||
1088 | * |
||
1089 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
1090 | */ |
||
1091 | 280 | public function newEloquentBuilder($query) |
|
1095 | |||
1096 | /** |
||
1097 | * Get a new base query that includes deleted nodes. |
||
1098 | * |
||
1099 | * @param string|null $table |
||
1100 | * |
||
1101 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
1102 | */ |
||
1103 | 116 | public function newNestedSetQuery($table = null) |
|
1111 | |||
1112 | /** |
||
1113 | * @param string|null $table |
||
1114 | * |
||
1115 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
1116 | */ |
||
1117 | 136 | public function newScopedQuery($table = null) |
|
1121 | |||
1122 | /** |
||
1123 | * @param \Illuminate\Database\Query\Builder $query |
||
1124 | * @param string $table |
||
1125 | * |
||
1126 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
1127 | */ |
||
1128 | 204 | public function applyNestedSetScope($query, $table = null) |
|
1144 | |||
1145 | /** |
||
1146 | * @return array |
||
1147 | */ |
||
1148 | 160 | protected function getScopeAttributes() |
|
1152 | |||
1153 | /** |
||
1154 | * @param array $attributes |
||
1155 | * |
||
1156 | * @return self |
||
1157 | */ |
||
1158 | 12 | public static function scoped(array $attributes) |
|
1166 | |||
1167 | /** |
||
1168 | * Create a new Eloquent Collection instance. |
||
1169 | * |
||
1170 | * @param array $models |
||
1171 | * |
||
1172 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection |
||
1173 | */ |
||
1174 | 228 | public function newCollection(array $models = []) |
|
1178 | |||
1179 | /** |
||
1180 | * Save a new model and return the instance. |
||
1181 | * |
||
1182 | * Use `children` key on `$attributes` to create child nodes. |
||
1183 | * |
||
1184 | * @param array $attributes |
||
1185 | * @param self $parent |
||
1186 | * |
||
1187 | * @return static |
||
1188 | */ |
||
1189 | 12 | public static function create(array $attributes = [], self $parent = null) |
|
1211 | |||
1212 | /* ------------------------------------------------------------------------------------------------ |
||
1213 | | Check Functions |
||
1214 | | ------------------------------------------------------------------------------------------------ |
||
1215 | */ |
||
1216 | /** |
||
1217 | * Get whether node is root. |
||
1218 | * |
||
1219 | * @return bool |
||
1220 | */ |
||
1221 | 16 | public function isRoot() |
|
1225 | |||
1226 | /** |
||
1227 | * Get whether a node is a descendant of other node. |
||
1228 | * |
||
1229 | * @param self $other |
||
1230 | * |
||
1231 | * @return bool |
||
1232 | */ |
||
1233 | 76 | public function isDescendantOf(self $other) |
|
1240 | |||
1241 | /** |
||
1242 | * Get whether the node is immediate children of other node. |
||
1243 | * |
||
1244 | * @param self $other |
||
1245 | * |
||
1246 | * @return bool |
||
1247 | */ |
||
1248 | 4 | public function isChildOf(self $other) |
|
1252 | |||
1253 | /** |
||
1254 | * Get whether the node is a sibling of another node. |
||
1255 | * |
||
1256 | * @param self $other |
||
1257 | * |
||
1258 | * @return bool |
||
1259 | */ |
||
1260 | 32 | public function isSiblingOf(self $other) |
|
1264 | |||
1265 | /** |
||
1266 | * Get whether the node is an ancestor of other node, including immediate parent. |
||
1267 | * |
||
1268 | * @param self $other |
||
1269 | * |
||
1270 | * @return bool |
||
1271 | */ |
||
1272 | 4 | public function isAncestorOf(self $other) |
|
1276 | |||
1277 | /** |
||
1278 | * Get whether the node has moved since last save. |
||
1279 | * |
||
1280 | * @return bool |
||
1281 | */ |
||
1282 | 24 | public function hasMoved() |
|
1286 | |||
1287 | /** |
||
1288 | * Check if the model uses soft delete. |
||
1289 | * |
||
1290 | * @return bool |
||
1291 | */ |
||
1292 | 280 | public static function usesSoftDelete() |
|
1304 | |||
1305 | /** |
||
1306 | * Get whether user is intended to delete the model from database entirely. |
||
1307 | * |
||
1308 | * @return bool |
||
1309 | */ |
||
1310 | 20 | protected function hardDeleting() |
|
1314 | |||
1315 | /* ------------------------------------------------------------------------------------------------ |
||
1316 | | Assertion Functions |
||
1317 | | ------------------------------------------------------------------------------------------------ |
||
1318 | */ |
||
1319 | /** |
||
1320 | * Assert that the node is not a descendant. |
||
1321 | * |
||
1322 | * @param self $node |
||
1323 | * |
||
1324 | * @return self |
||
1325 | */ |
||
1326 | 76 | protected function assertNotDescendant(self $node) |
|
1334 | |||
1335 | /** |
||
1336 | * Assert node exists. |
||
1337 | * |
||
1338 | * @param self $node |
||
1339 | * |
||
1340 | * @return self |
||
1341 | */ |
||
1342 | 76 | protected function assertNodeExists(self $node) |
|
1350 | } |
||
1351 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: