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 |
||
| 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() |
|
| 107 | |||
| 108 | /* ------------------------------------------------------------------------------------------------ |
||
| 109 | | Eloquent Functions |
||
| 110 | | ------------------------------------------------------------------------------------------------ |
||
| 111 | */ |
||
| 112 | /** |
||
| 113 | * Get the database connection for the model. |
||
| 114 | * |
||
| 115 | * @return \Illuminate\Database\Connection |
||
| 116 | */ |
||
| 117 | abstract public function getConnection(); |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Get the table associated with the model. |
||
| 121 | * |
||
| 122 | * @return string |
||
| 123 | */ |
||
| 124 | abstract public function getTable(); |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Get the value of the model's primary key. |
||
| 128 | * |
||
| 129 | * @return mixed |
||
| 130 | */ |
||
| 131 | abstract public function getKey(); |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Get the primary key for the model. |
||
| 135 | * |
||
| 136 | * @return string |
||
| 137 | */ |
||
| 138 | abstract public function getKeyName(); |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Get a plain attribute (not a relationship). |
||
| 142 | * |
||
| 143 | * @param string $key |
||
| 144 | * |
||
| 145 | * @return mixed |
||
| 146 | */ |
||
| 147 | abstract public function getAttributeValue($key); |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Set the array of model attributes. No checking is done. |
||
| 151 | * |
||
| 152 | * @param array $attributes |
||
| 153 | * @param bool $sync |
||
| 154 | * |
||
| 155 | * @return self |
||
| 156 | */ |
||
| 157 | abstract public function setRawAttributes(array $attributes, $sync = false); |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Set the specific relationship in the model. |
||
| 161 | * |
||
| 162 | * @param string $relation |
||
| 163 | * @param mixed $value |
||
| 164 | * |
||
| 165 | * @return self |
||
| 166 | */ |
||
| 167 | abstract public function setRelation($relation, $value); |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Get a relationship. |
||
| 171 | * |
||
| 172 | * @param string $key |
||
| 173 | * |
||
| 174 | * @return mixed |
||
| 175 | */ |
||
| 176 | abstract public function getRelationValue($key); |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Determine if the model or given attribute(s) have been modified. |
||
| 180 | * |
||
| 181 | * @param array|string|null $attributes |
||
| 182 | * |
||
| 183 | * @return bool |
||
| 184 | */ |
||
| 185 | abstract public function isDirty($attributes = null); |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Fill the model with an array of attributes. |
||
| 189 | * |
||
| 190 | * @param array $attributes |
||
| 191 | * |
||
| 192 | * @return self |
||
| 193 | * |
||
| 194 | * @throws \Illuminate\Database\Eloquent\MassAssignmentException |
||
| 195 | */ |
||
| 196 | abstract public function fill(array $attributes); |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Save the model to the database. |
||
| 200 | * |
||
| 201 | * @param array $options |
||
| 202 | * |
||
| 203 | * @return bool |
||
| 204 | */ |
||
| 205 | abstract public function save(array $options = []); |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Get a new query builder for the model's table. |
||
| 209 | * |
||
| 210 | * @return \Illuminate\Database\Eloquent\Builder |
||
| 211 | */ |
||
| 212 | abstract public function newQuery(); |
||
| 213 | |||
| 214 | /* ------------------------------------------------------------------------------------------------ |
||
| 215 | | Relationships |
||
| 216 | | ------------------------------------------------------------------------------------------------ |
||
| 217 | */ |
||
| 218 | /** |
||
| 219 | * Relation to the parent. |
||
| 220 | * |
||
| 221 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
| 222 | */ |
||
| 223 | 16 | public function parent() |
|
| 228 | |||
| 229 | /** |
||
| 230 | * Relation to children. |
||
| 231 | * |
||
| 232 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
| 233 | */ |
||
| 234 | 16 | public function children() |
|
| 239 | |||
| 240 | /** |
||
| 241 | * Get query for descendants of the node. |
||
| 242 | * |
||
| 243 | * @return \Arcanedev\LaravelNestedSet\Eloquent\DescendantsRelation |
||
| 244 | */ |
||
| 245 | 43 | public function descendants() |
|
| 249 | |||
| 250 | /** |
||
| 251 | * Get query for siblings of the node. |
||
| 252 | * |
||
| 253 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
| 254 | */ |
||
| 255 | 8 | public function siblings() |
|
| 261 | |||
| 262 | /* ------------------------------------------------------------------------------------------------ |
||
| 263 | | Getters & Setters |
||
| 264 | | ------------------------------------------------------------------------------------------------ |
||
| 265 | */ |
||
| 266 | /** |
||
| 267 | * Get the lft key name. |
||
| 268 | * |
||
| 269 | * @return string |
||
| 270 | */ |
||
| 271 | 208 | public function getLftName() |
|
| 275 | |||
| 276 | /** |
||
| 277 | * Get the rgt key name. |
||
| 278 | * |
||
| 279 | * @return string |
||
| 280 | */ |
||
| 281 | 180 | public function getRgtName() |
|
| 285 | |||
| 286 | /** |
||
| 287 | * Get the parent id key name. |
||
| 288 | * |
||
| 289 | * @return string |
||
| 290 | */ |
||
| 291 | 140 | public function getParentIdName() |
|
| 295 | |||
| 296 | /** |
||
| 297 | * Get the value of the model's lft key. |
||
| 298 | * |
||
| 299 | * @return int |
||
| 300 | */ |
||
| 301 | 177 | public function getLft() |
|
| 305 | |||
| 306 | /** |
||
| 307 | * Set the value of the model's lft key. |
||
| 308 | * |
||
| 309 | * @param int $value |
||
| 310 | * |
||
| 311 | * @return self |
||
| 312 | */ |
||
| 313 | 91 | public function setLft($value) |
|
| 319 | |||
| 320 | /** |
||
| 321 | * Get the value of the model's rgt key. |
||
| 322 | * |
||
| 323 | * @return int |
||
| 324 | */ |
||
| 325 | 119 | public function getRgt() |
|
| 329 | |||
| 330 | /** |
||
| 331 | * Set the value of the model's rgt key. |
||
| 332 | * |
||
| 333 | * @param int $value |
||
| 334 | * |
||
| 335 | * @return self |
||
| 336 | */ |
||
| 337 | 91 | public function setRgt($value) |
|
| 343 | |||
| 344 | /** |
||
| 345 | * Get the value of the model's parent id key. |
||
| 346 | * |
||
| 347 | * @return int |
||
| 348 | */ |
||
| 349 | 96 | public function getParentId() |
|
| 353 | |||
| 354 | /** |
||
| 355 | * Set the value of the model's parent id key. |
||
| 356 | * |
||
| 357 | * @param int $value |
||
| 358 | * |
||
| 359 | * @return self |
||
| 360 | */ |
||
| 361 | 63 | public function setParentId($value) |
|
| 367 | |||
| 368 | /** |
||
| 369 | * Apply parent model. |
||
| 370 | * |
||
| 371 | * @param \Illuminate\Database\Eloquent\Model|null $value |
||
| 372 | * |
||
| 373 | * @return self |
||
| 374 | */ |
||
| 375 | 55 | protected function setParent($value) |
|
| 382 | |||
| 383 | /** |
||
| 384 | * Set the value of model's parent id key. |
||
| 385 | * |
||
| 386 | * Behind the scenes node is appended to found parent node. |
||
| 387 | * |
||
| 388 | * @param int $value |
||
| 389 | * |
||
| 390 | * @throws Exception If parent node doesn't exists |
||
| 391 | */ |
||
| 392 | 12 | public function setParentIdAttribute($value) |
|
| 405 | |||
| 406 | /** |
||
| 407 | * Get the boundaries. |
||
| 408 | * |
||
| 409 | * @return array |
||
| 410 | */ |
||
| 411 | 43 | public function getBounds() |
|
| 415 | |||
| 416 | /** |
||
| 417 | * Set the lft and rgt boundaries to null. |
||
| 418 | * |
||
| 419 | * @return self |
||
| 420 | */ |
||
| 421 | 68 | protected function dirtyBounds() |
|
| 425 | |||
| 426 | /** |
||
| 427 | * Returns node that is next to current node without constraining to siblings. |
||
| 428 | * This can be either a next sibling or a next sibling of the parent node. |
||
| 429 | * |
||
| 430 | * @param array $columns |
||
| 431 | * |
||
| 432 | * @return self |
||
| 433 | */ |
||
| 434 | public function getNextNode(array $columns = ['*']) |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Returns node that is before current node without constraining to siblings. |
||
| 441 | * This can be either a prev sibling or parent node. |
||
| 442 | * |
||
| 443 | * @param array $columns |
||
| 444 | * |
||
| 445 | * @return self |
||
| 446 | */ |
||
| 447 | 4 | public function getPrevNode(array $columns = ['*']) |
|
| 451 | |||
| 452 | /** |
||
| 453 | * Get the ancestors nodes. |
||
| 454 | * |
||
| 455 | * @param array $columns |
||
| 456 | * |
||
| 457 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection |
||
| 458 | */ |
||
| 459 | 8 | public function getAncestors(array $columns = ['*']) |
|
| 465 | |||
| 466 | /** |
||
| 467 | * Get the descendants nodes. |
||
| 468 | * |
||
| 469 | * @param array $columns |
||
| 470 | * |
||
| 471 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection|self[] |
||
| 472 | */ |
||
| 473 | 12 | public function getDescendants(array $columns = ['*']) |
|
| 477 | |||
| 478 | /** |
||
| 479 | * Get the siblings nodes. |
||
| 480 | * |
||
| 481 | * @param array $columns |
||
| 482 | * |
||
| 483 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection|self[] |
||
| 484 | */ |
||
| 485 | 8 | public function getSiblings(array $columns = ['*']) |
|
| 489 | |||
| 490 | /** |
||
| 491 | * Get the next siblings nodes. |
||
| 492 | * |
||
| 493 | * @param array $columns |
||
| 494 | * |
||
| 495 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection|self[] |
||
| 496 | */ |
||
| 497 | 8 | public function getNextSiblings(array $columns = ['*']) |
|
| 501 | |||
| 502 | /** |
||
| 503 | * Get the previous siblings nodes. |
||
| 504 | * |
||
| 505 | * @param array $columns |
||
| 506 | * |
||
| 507 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection|self[] |
||
| 508 | */ |
||
| 509 | 8 | public function getPrevSiblings(array $columns = ['*']) |
|
| 513 | |||
| 514 | /** |
||
| 515 | * Get the next sibling node. |
||
| 516 | * |
||
| 517 | * @param array $columns |
||
| 518 | * |
||
| 519 | * @return self |
||
| 520 | */ |
||
| 521 | 4 | public function getNextSibling(array $columns = ['*']) |
|
| 525 | |||
| 526 | /** |
||
| 527 | * Get the previous sibling node. |
||
| 528 | * |
||
| 529 | * @param array $columns |
||
| 530 | * |
||
| 531 | * @return self |
||
| 532 | */ |
||
| 533 | 4 | public function getPrevSibling(array $columns = ['*']) |
|
| 537 | |||
| 538 | /** |
||
| 539 | * Get node height (rgt - lft + 1). |
||
| 540 | * |
||
| 541 | * @return int |
||
| 542 | */ |
||
| 543 | 36 | public function getNodeHeight() |
|
| 549 | |||
| 550 | /** |
||
| 551 | * Get number of descendant nodes. |
||
| 552 | * |
||
| 553 | * @return int |
||
| 554 | */ |
||
| 555 | 4 | public function getDescendantCount() |
|
| 559 | |||
| 560 | /** |
||
| 561 | * Get an attribute array of all arrayable relations. |
||
| 562 | * |
||
| 563 | * @return array |
||
| 564 | */ |
||
| 565 | protected function getArrayableRelations() |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Set an action. |
||
| 576 | * |
||
| 577 | * @param string $action |
||
| 578 | * |
||
| 579 | * @return $this |
||
| 580 | */ |
||
| 581 | 114 | protected function setNodeAction($action) |
|
| 587 | |||
| 588 | /** |
||
| 589 | * @return bool |
||
| 590 | */ |
||
| 591 | 8 | protected function actionRaw() |
|
| 595 | |||
| 596 | /** |
||
| 597 | * Call pending action. |
||
| 598 | * |
||
| 599 | * @return null|false |
||
| 600 | */ |
||
| 601 | 92 | protected function callPendingAction() |
|
| 617 | |||
| 618 | /* ------------------------------------------------------------------------------------------------ |
||
| 619 | | Other Functions |
||
| 620 | | ------------------------------------------------------------------------------------------------ |
||
| 621 | */ |
||
| 622 | /** |
||
| 623 | * Make a root node. |
||
| 624 | */ |
||
| 625 | 30 | protected function actionRoot() |
|
| 645 | |||
| 646 | /** |
||
| 647 | * Get the lower bound. |
||
| 648 | * |
||
| 649 | * @return int |
||
| 650 | */ |
||
| 651 | 30 | protected function getLowerBound() |
|
| 655 | |||
| 656 | /** |
||
| 657 | * Append or prepend a node to the parent. |
||
| 658 | * |
||
| 659 | * @param self $parent |
||
| 660 | * @param bool $prepend |
||
| 661 | * |
||
| 662 | * @return bool |
||
| 663 | */ |
||
| 664 | 32 | protected function actionAppendOrPrepend(self $parent, $prepend = false) |
|
| 678 | |||
| 679 | /** |
||
| 680 | * Insert node before or after another node. |
||
| 681 | * |
||
| 682 | * @param self $node |
||
| 683 | * @param bool $after |
||
| 684 | * |
||
| 685 | * @return bool |
||
| 686 | */ |
||
| 687 | 26 | protected function actionBeforeOrAfter(self $node, $after = false) |
|
| 693 | |||
| 694 | /** |
||
| 695 | * Refresh node's crucial attributes. |
||
| 696 | */ |
||
| 697 | 84 | public function refreshNode() |
|
| 706 | |||
| 707 | /** |
||
| 708 | * Get query for siblings after the node. |
||
| 709 | * |
||
| 710 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
| 711 | */ |
||
| 712 | 24 | public function nextSiblings() |
|
| 717 | |||
| 718 | /** |
||
| 719 | * Get query for siblings before the node. |
||
| 720 | * |
||
| 721 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
| 722 | */ |
||
| 723 | 16 | public function prevSiblings() |
|
| 728 | |||
| 729 | /** |
||
| 730 | * Get query for nodes after current node. |
||
| 731 | * |
||
| 732 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
| 733 | */ |
||
| 734 | 28 | public function nextNodes() |
|
| 739 | |||
| 740 | /** |
||
| 741 | * Get query for nodes before current node in reversed order. |
||
| 742 | * |
||
| 743 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
| 744 | */ |
||
| 745 | 20 | public function prevNodes() |
|
| 750 | |||
| 751 | /** |
||
| 752 | * Get query for ancestors to the node not including the node itself. |
||
| 753 | * |
||
| 754 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
| 755 | */ |
||
| 756 | 4 | public function ancestors() |
|
| 761 | |||
| 762 | /** |
||
| 763 | * Make this node a root node. |
||
| 764 | * |
||
| 765 | * @return self |
||
| 766 | */ |
||
| 767 | 46 | public function makeRoot() |
|
| 771 | |||
| 772 | /** |
||
| 773 | * Save node as root. |
||
| 774 | * |
||
| 775 | * @return bool |
||
| 776 | */ |
||
| 777 | 8 | public function saveAsRoot() |
|
| 785 | |||
| 786 | /** |
||
| 787 | * Append and save a node. |
||
| 788 | * |
||
| 789 | * @param self $node |
||
| 790 | * |
||
| 791 | * @return bool |
||
| 792 | */ |
||
| 793 | 16 | public function appendNode(self $node) |
|
| 797 | |||
| 798 | /** |
||
| 799 | * Prepend and save a node. |
||
| 800 | * |
||
| 801 | * @param self $node |
||
| 802 | * |
||
| 803 | * @return bool |
||
| 804 | */ |
||
| 805 | 4 | public function prependNode(self $node) |
|
| 809 | |||
| 810 | /** |
||
| 811 | * Append a node to the new parent. |
||
| 812 | * |
||
| 813 | * @param self $parent |
||
| 814 | * |
||
| 815 | * @return self |
||
| 816 | */ |
||
| 817 | 40 | public function appendToNode(self $parent) |
|
| 821 | |||
| 822 | /** |
||
| 823 | * Prepend a node to the new parent. |
||
| 824 | * |
||
| 825 | * @param self $parent |
||
| 826 | * |
||
| 827 | * @return self |
||
| 828 | */ |
||
| 829 | 4 | public function prependToNode(self $parent) |
|
| 833 | |||
| 834 | /** |
||
| 835 | * @param self $parent |
||
| 836 | * @param bool $prepend |
||
| 837 | * |
||
| 838 | * @return self |
||
| 839 | */ |
||
| 840 | 44 | public function appendOrPrependTo(self $parent, $prepend = false) |
|
| 849 | |||
| 850 | /** |
||
| 851 | * Insert self after a node. |
||
| 852 | * |
||
| 853 | * @param self $node |
||
| 854 | * |
||
| 855 | * @return self |
||
| 856 | */ |
||
| 857 | 28 | public function afterNode(self $node) |
|
| 861 | |||
| 862 | /** |
||
| 863 | * Insert self before node. |
||
| 864 | * |
||
| 865 | * @param self $node |
||
| 866 | * |
||
| 867 | * @return self |
||
| 868 | */ |
||
| 869 | 8 | public function beforeNode(self $node) |
|
| 873 | |||
| 874 | /** |
||
| 875 | * @param self $node |
||
| 876 | * @param bool $after |
||
| 877 | * |
||
| 878 | * @return self |
||
| 879 | */ |
||
| 880 | 36 | public function beforeOrAfterNode(self $node, $after = false) |
|
| 892 | |||
| 893 | /** |
||
| 894 | * Insert self after a node and save. |
||
| 895 | * |
||
| 896 | * @param self $node |
||
| 897 | * |
||
| 898 | * @return bool |
||
| 899 | */ |
||
| 900 | 16 | public function insertAfterNode(self $node) |
|
| 904 | |||
| 905 | /** |
||
| 906 | * Insert self before a node and save. |
||
| 907 | * |
||
| 908 | * @param self $node |
||
| 909 | * |
||
| 910 | * @return bool |
||
| 911 | */ |
||
| 912 | 4 | public function insertBeforeNode(self $node) |
|
| 921 | |||
| 922 | /** |
||
| 923 | * @param int $lft |
||
| 924 | * @param int $rgt |
||
| 925 | * @param int $parentId |
||
| 926 | * |
||
| 927 | * @return self |
||
| 928 | */ |
||
| 929 | 8 | public function rawNode($lft, $rgt, $parentId) |
|
| 935 | |||
| 936 | /** |
||
| 937 | * Move node up given amount of positions. |
||
| 938 | * |
||
| 939 | * @param int $amount |
||
| 940 | * |
||
| 941 | * @return bool |
||
| 942 | */ |
||
| 943 | 4 | public function up($amount = 1) |
|
| 954 | |||
| 955 | /** |
||
| 956 | * Move node down given amount of positions. |
||
| 957 | * |
||
| 958 | * @param int $amount |
||
| 959 | * |
||
| 960 | * @return bool |
||
| 961 | */ |
||
| 962 | 16 | public function down($amount = 1) |
|
| 973 | |||
| 974 | /** |
||
| 975 | * Insert node at specific position. |
||
| 976 | * |
||
| 977 | * @param int $position |
||
| 978 | * |
||
| 979 | * @return bool |
||
| 980 | */ |
||
| 981 | 65 | protected function insertAt($position) |
|
| 991 | |||
| 992 | /** |
||
| 993 | * Move a node to the new position. |
||
| 994 | * |
||
| 995 | * @param int $position |
||
| 996 | * |
||
| 997 | * @return int |
||
| 998 | */ |
||
| 999 | 37 | protected function moveNode($position) |
|
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Insert new node at specified position. |
||
| 1011 | * |
||
| 1012 | * @param int $position |
||
| 1013 | * |
||
| 1014 | * @return bool |
||
| 1015 | */ |
||
| 1016 | 32 | protected function insertNode($position) |
|
| 1027 | |||
| 1028 | /** |
||
| 1029 | * Update the tree when the node is removed physically. |
||
| 1030 | */ |
||
| 1031 | 19 | protected function deleteDescendants() |
|
| 1053 | |||
| 1054 | /** |
||
| 1055 | * Restore the descendants. |
||
| 1056 | * |
||
| 1057 | * @param mixed $deletedAt |
||
| 1058 | */ |
||
| 1059 | 4 | protected function restoreDescendants($deletedAt) |
|
| 1066 | |||
| 1067 | /** |
||
| 1068 | * Create a new Eloquent query builder for the model. |
||
| 1069 | * |
||
| 1070 | * @param \Illuminate\Database\Query\Builder $query |
||
| 1071 | * |
||
| 1072 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
| 1073 | */ |
||
| 1074 | 280 | public function newEloquentBuilder($query) |
|
| 1078 | |||
| 1079 | /** |
||
| 1080 | * Get a new base query that includes deleted nodes. |
||
| 1081 | * |
||
| 1082 | * @param string|null $table |
||
| 1083 | * |
||
| 1084 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
| 1085 | */ |
||
| 1086 | 111 | public function newNestedSetQuery($table = null) |
|
| 1094 | |||
| 1095 | /** |
||
| 1096 | * @param string|null $table |
||
| 1097 | * |
||
| 1098 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
| 1099 | */ |
||
| 1100 | 135 | public function newScopedQuery($table = null) |
|
| 1104 | |||
| 1105 | /** |
||
| 1106 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
| 1107 | * @param string $table |
||
| 1108 | * |
||
| 1109 | * @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
| 1110 | */ |
||
| 1111 | 201 | public function applyNestedSetScope($query, $table = null) |
|
| 1127 | |||
| 1128 | /** |
||
| 1129 | * @return array |
||
| 1130 | */ |
||
| 1131 | 160 | protected function getScopeAttributes() |
|
| 1135 | |||
| 1136 | /** |
||
| 1137 | * @param array $attributes |
||
| 1138 | * |
||
| 1139 | * @return self |
||
| 1140 | */ |
||
| 1141 | 12 | public static function scoped(array $attributes) |
|
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Create a new Eloquent Collection instance. |
||
| 1152 | * |
||
| 1153 | * @param array $models |
||
| 1154 | * |
||
| 1155 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection |
||
| 1156 | */ |
||
| 1157 | 227 | public function newCollection(array $models = []) |
|
| 1161 | |||
| 1162 | /** |
||
| 1163 | * Save a new model and return the instance. |
||
| 1164 | * |
||
| 1165 | * Use `children` key on `$attributes` to create child nodes. |
||
| 1166 | * |
||
| 1167 | * @param array $attributes |
||
| 1168 | * @param self $parent |
||
| 1169 | * |
||
| 1170 | * @return static |
||
| 1171 | */ |
||
| 1172 | 12 | public static function create(array $attributes = [], self $parent = null) |
|
| 1194 | |||
| 1195 | /* ------------------------------------------------------------------------------------------------ |
||
| 1196 | | Check Functions |
||
| 1197 | | ------------------------------------------------------------------------------------------------ |
||
| 1198 | */ |
||
| 1199 | /** |
||
| 1200 | * Get whether node is root. |
||
| 1201 | * |
||
| 1202 | * @return bool |
||
| 1203 | */ |
||
| 1204 | 16 | public function isRoot() |
|
| 1208 | |||
| 1209 | /** |
||
| 1210 | * Get whether a node is a descendant of other node. |
||
| 1211 | * |
||
| 1212 | * @param self $other |
||
| 1213 | * |
||
| 1214 | * @return bool |
||
| 1215 | */ |
||
| 1216 | 76 | public function isDescendantOf(self $other) |
|
| 1223 | |||
| 1224 | /** |
||
| 1225 | * Get whether the node is immediate children of other node. |
||
| 1226 | * |
||
| 1227 | * @param self $other |
||
| 1228 | * |
||
| 1229 | * @return bool |
||
| 1230 | */ |
||
| 1231 | 4 | public function isChildOf(self $other) |
|
| 1235 | |||
| 1236 | /** |
||
| 1237 | * Get whether the node is a sibling of another node. |
||
| 1238 | * |
||
| 1239 | * @param self $other |
||
| 1240 | * |
||
| 1241 | * @return bool |
||
| 1242 | */ |
||
| 1243 | 32 | public function isSiblingOf(self $other) |
|
| 1247 | |||
| 1248 | /** |
||
| 1249 | * Get whether the node is an ancestor of other node, including immediate parent. |
||
| 1250 | * |
||
| 1251 | * @param self $other |
||
| 1252 | * |
||
| 1253 | * @return bool |
||
| 1254 | */ |
||
| 1255 | 4 | public function isAncestorOf(self $other) |
|
| 1259 | |||
| 1260 | /** |
||
| 1261 | * Get whether the node has moved since last save. |
||
| 1262 | * |
||
| 1263 | * @return bool |
||
| 1264 | */ |
||
| 1265 | 24 | public function hasMoved() |
|
| 1269 | |||
| 1270 | /** |
||
| 1271 | * Check if the model uses soft delete. |
||
| 1272 | * |
||
| 1273 | * @return bool |
||
| 1274 | */ |
||
| 1275 | 280 | public static function usesSoftDelete() |
|
| 1287 | |||
| 1288 | /** |
||
| 1289 | * Get whether user is intended to delete the model from database entirely. |
||
| 1290 | * |
||
| 1291 | * @return bool |
||
| 1292 | */ |
||
| 1293 | 19 | protected function hardDeleting() |
|
| 1297 | |||
| 1298 | /* ------------------------------------------------------------------------------------------------ |
||
| 1299 | | Assertion Functions |
||
| 1300 | | ------------------------------------------------------------------------------------------------ |
||
| 1301 | */ |
||
| 1302 | /** |
||
| 1303 | * Assert that the node is not a descendant. |
||
| 1304 | * |
||
| 1305 | * @param self $node |
||
| 1306 | * |
||
| 1307 | * @return self |
||
| 1308 | */ |
||
| 1309 | 76 | protected function assertNotDescendant(self $node) |
|
| 1317 | |||
| 1318 | /** |
||
| 1319 | * Assert node exists. |
||
| 1320 | * |
||
| 1321 | * @param self $node |
||
| 1322 | * |
||
| 1323 | * @return self |
||
| 1324 | */ |
||
| 1325 | 76 | protected function assertNodeExists(self $node) |
|
| 1333 | } |
||
| 1334 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.