Complex classes like AbstractNode 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 AbstractNode, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | abstract class AbstractNode implements NodeInterface |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * name max lenght. |
||
| 33 | */ |
||
| 34 | const MAX_NAME_LENGTH = 255; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Unique id. |
||
| 38 | * |
||
| 39 | * @var ObjectId |
||
| 40 | */ |
||
| 41 | protected $_id; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Node name. |
||
| 45 | * |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | protected $name = ''; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Owner. |
||
| 52 | * |
||
| 53 | * @var ObjectId |
||
| 54 | */ |
||
| 55 | protected $owner; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Mime. |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | protected $mime; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Meta attributes. |
||
| 66 | * |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | protected $meta = []; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Parent collection. |
||
| 73 | * |
||
| 74 | * @var ObjectId |
||
| 75 | */ |
||
| 76 | protected $parent; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Is file deleted. |
||
| 80 | * |
||
| 81 | * @var bool|UTCDateTime |
||
| 82 | */ |
||
| 83 | protected $deleted = false; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Is shared? |
||
| 87 | * |
||
| 88 | * @var bool |
||
| 89 | */ |
||
| 90 | protected $shared = false; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Destory at a certain time. |
||
| 94 | * |
||
| 95 | * @var UTCDateTime |
||
| 96 | */ |
||
| 97 | protected $destroy; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Changed timestamp. |
||
| 101 | * |
||
| 102 | * @var UTCDateTime |
||
| 103 | */ |
||
| 104 | protected $changed; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Created timestamp. |
||
| 108 | * |
||
| 109 | * @var UTCDateTime |
||
| 110 | */ |
||
| 111 | protected $created; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Point to antother node (Means this node is reference to $reference). |
||
| 115 | * |
||
| 116 | * @var ObjectId |
||
| 117 | */ |
||
| 118 | protected $reference; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Raw attributes before any processing or modifications. |
||
| 122 | * |
||
| 123 | * @var array |
||
| 124 | */ |
||
| 125 | protected $raw_attributes; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Readonly flag. |
||
| 129 | * |
||
| 130 | * @var bool |
||
| 131 | */ |
||
| 132 | protected $readonly = false; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * App attributes. |
||
| 136 | * |
||
| 137 | * @var array |
||
| 138 | */ |
||
| 139 | protected $app = []; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Filesystem. |
||
| 143 | * |
||
| 144 | * @var Filesystem |
||
| 145 | */ |
||
| 146 | protected $_fs; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Database. |
||
| 150 | * |
||
| 151 | * @var Database |
||
| 152 | */ |
||
| 153 | protected $_db; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * User. |
||
| 157 | * |
||
| 158 | * @var User |
||
| 159 | */ |
||
| 160 | protected $_user; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Logger. |
||
| 164 | * |
||
| 165 | * @var LoggerInterface |
||
| 166 | */ |
||
| 167 | protected $_logger; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Server. |
||
| 171 | * |
||
| 172 | * @var Server |
||
| 173 | */ |
||
| 174 | protected $_server; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Hook. |
||
| 178 | * |
||
| 179 | * @var Hook |
||
| 180 | */ |
||
| 181 | protected $_hook; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Acl. |
||
| 185 | * |
||
| 186 | * @var Acl |
||
| 187 | */ |
||
| 188 | protected $_acl; |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Mount. |
||
| 192 | * |
||
| 193 | * @var ObjectId |
||
| 194 | */ |
||
| 195 | protected $storage_reference; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Storage attributes. |
||
| 199 | * |
||
| 200 | * @var array |
||
| 201 | */ |
||
| 202 | protected $storage; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Acl. |
||
| 206 | * |
||
| 207 | * @var array |
||
| 208 | */ |
||
| 209 | protected $acl = []; |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Mount. |
||
| 213 | * |
||
| 214 | * @var array |
||
| 215 | */ |
||
| 216 | protected $mount = []; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Parent collection. |
||
| 220 | * |
||
| 221 | * @var Collection |
||
| 222 | */ |
||
| 223 | protected $_parent; |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Convert to filename. |
||
| 227 | * |
||
| 228 | * @return string |
||
| 229 | */ |
||
| 230 | public function __toString() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Get owner. |
||
| 237 | */ |
||
| 238 | public function getOwner(): ObjectId |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Set filesystem. |
||
| 245 | */ |
||
| 246 | public function setFilesystem(Filesystem $fs): NodeInterface |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Get filesystem. |
||
| 256 | */ |
||
| 257 | public function getFilesystem(): Filesystem |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Check if $node is a sub node of any parent nodes of this node. |
||
| 264 | */ |
||
| 265 | public function isSubNode(NodeInterface $node): bool |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Move node. |
||
| 286 | */ |
||
| 287 | public function setParent(Collection $parent, int $conflict = NodeInterface::CONFLICT_NOACTION): NodeInterface |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Set node acl. |
||
| 371 | */ |
||
| 372 | public function setAcl(array $acl): NodeInterface |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Get ACL. |
||
| 394 | */ |
||
| 395 | public function getAcl(): array |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Get share id. |
||
| 408 | */ |
||
| 409 | public function getShareId(bool $reference = false): ?ObjectId |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Get share node. |
||
| 432 | * |
||
| 433 | * @return Collection |
||
| 434 | */ |
||
| 435 | public function getShareNode(): ?Collection |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Is node marked as readonly? |
||
| 450 | */ |
||
| 451 | public function isReadonly(): bool |
||
| 455 | |||
| 456 | /** |
||
| 457 | * Request is from node owner? |
||
| 458 | */ |
||
| 459 | public function isOwnerRequest(): bool |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Check if node is kind of special. |
||
| 466 | */ |
||
| 467 | public function isSpecial(): bool |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Check if node is a sub node of a share. |
||
| 484 | */ |
||
| 485 | public function isShareMember(): bool |
||
| 489 | |||
| 490 | /** |
||
| 491 | * Check if node is a sub node of an external storage mount. |
||
| 492 | */ |
||
| 493 | public function isMountMember(): bool |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Is share. |
||
| 500 | */ |
||
| 501 | public function isShare(): bool |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Is share (Reference or master share). |
||
| 508 | */ |
||
| 509 | public function isShared(): bool |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Set the name. |
||
| 520 | */ |
||
| 521 | public function setName($name): bool |
||
| 546 | |||
| 547 | /** |
||
| 548 | * Check name. |
||
| 549 | */ |
||
| 550 | public function checkName(string $name): string |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Get the name. |
||
| 568 | */ |
||
| 569 | public function getName(): string |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Get mount node. |
||
| 576 | */ |
||
| 577 | public function getMount(): ?ObjectId |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Undelete. |
||
| 584 | */ |
||
| 585 | public function undelete(int $conflict = NodeInterface::CONFLICT_NOACTION, ?string $recursion = null, bool $recursion_first = true): bool |
||
| 647 | |||
| 648 | /** |
||
| 649 | * Is node deleted? |
||
| 650 | */ |
||
| 651 | public function isDeleted(): bool |
||
| 655 | |||
| 656 | /** |
||
| 657 | * Get last modified timestamp. |
||
| 658 | */ |
||
| 659 | public function getLastModified(): int |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Get unique id. |
||
| 670 | * |
||
| 671 | * @return ObjectId |
||
| 672 | */ |
||
| 673 | 1 | public function getId(): ?ObjectId |
|
| 677 | |||
| 678 | /** |
||
| 679 | * Get parent. |
||
| 680 | */ |
||
| 681 | public function getParent(): ?Collection |
||
| 685 | |||
| 686 | /** |
||
| 687 | * Get parents. |
||
| 688 | */ |
||
| 689 | public function getParents(?NodeInterface $node = null, array $parents = []): array |
||
| 703 | |||
| 704 | /** |
||
| 705 | * Get as zip. |
||
| 706 | */ |
||
| 707 | public function getZip(): void |
||
| 713 | |||
| 714 | /** |
||
| 715 | * Create zip. |
||
| 716 | * |
||
| 717 | * @param bool $self true means that the zip represents the collection itself instead a child of the zip |
||
| 718 | * @param NodeInterface $parent |
||
| 719 | */ |
||
| 720 | public function zip(ZipStream $archive, bool $self = true, ?NodeInterface $parent = null, string $path = '', int $depth = 0): bool |
||
| 765 | |||
| 766 | /** |
||
| 767 | * Get mime type. |
||
| 768 | */ |
||
| 769 | 1 | public function getContentType(): string |
|
| 773 | |||
| 774 | /** |
||
| 775 | * Is reference. |
||
| 776 | */ |
||
| 777 | public function isReference(): bool |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Set app attributes. |
||
| 784 | */ |
||
| 785 | public function setAppAttributes(string $namespace, array $attributes): NodeInterface |
||
| 792 | |||
| 793 | /** |
||
| 794 | * Set app attribute. |
||
| 795 | */ |
||
| 796 | public function setAppAttribute(string $namespace, string $attribute, $value): NodeInterface |
||
| 807 | |||
| 808 | /** |
||
| 809 | * Remove app attribute. |
||
| 810 | */ |
||
| 811 | public function unsetAppAttributes(string $namespace): NodeInterface |
||
| 820 | |||
| 821 | /** |
||
| 822 | * Remove app attribute. |
||
| 823 | */ |
||
| 824 | public function unsetAppAttribute(string $namespace, string $attribute): NodeInterface |
||
| 833 | |||
| 834 | /** |
||
| 835 | * Get app attribute. |
||
| 836 | */ |
||
| 837 | public function getAppAttribute(string $namespace, string $attribute) |
||
| 845 | |||
| 846 | /** |
||
| 847 | * Get app attributes. |
||
| 848 | */ |
||
| 849 | public function getAppAttributes(string $namespace): array |
||
| 857 | |||
| 858 | /** |
||
| 859 | * Set meta attributes. |
||
| 860 | */ |
||
| 861 | public function setMetaAttributes(array $attributes): NodeInterface |
||
| 876 | |||
| 877 | /** |
||
| 878 | * Get meta attributes as array. |
||
| 879 | */ |
||
| 880 | public function getMetaAttributes(array $attributes = []): array |
||
| 889 | |||
| 890 | /** |
||
| 891 | * Mark node as readonly. |
||
| 892 | */ |
||
| 893 | public function setReadonly(bool $readonly = true): bool |
||
| 900 | |||
| 901 | /** |
||
| 902 | * Mark node as self-destroyable. |
||
| 903 | */ |
||
| 904 | public function setDestroyable(?UTCDateTime $ts): bool |
||
| 914 | |||
| 915 | /** |
||
| 916 | * Get original raw attributes before any processing. |
||
| 917 | */ |
||
| 918 | public function getRawAttributes(): array |
||
| 922 | |||
| 923 | /** |
||
| 924 | * Check if node is in root. |
||
| 925 | */ |
||
| 926 | public function isInRoot(): bool |
||
| 930 | |||
| 931 | /** |
||
| 932 | * Check if node is an instance of the actual root collection. |
||
| 933 | */ |
||
| 934 | public function isRoot(): bool |
||
| 938 | |||
| 939 | /** |
||
| 940 | * Resolve node path. |
||
| 941 | */ |
||
| 942 | public function getPath(): string |
||
| 953 | |||
| 954 | /** |
||
| 955 | * Save node attributes. |
||
| 956 | * |
||
| 957 | * @param array|string $attributes |
||
| 958 | * @param array|string $remove |
||
| 959 | * @param string $recursion |
||
| 960 | */ |
||
| 961 | public function save($attributes = [], $remove = [], ?string $recursion = null, bool $recursion_first = true): bool |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Get array value via string path. |
||
| 1028 | */ |
||
| 1029 | protected function getArrayValue(Iterable $array, string $path, string $separator = '.') |
||
| 1046 | |||
| 1047 | /** |
||
| 1048 | * Validate meta attributes. |
||
| 1049 | */ |
||
| 1050 | protected function validateMetaAttributes(array $attributes): array |
||
| 1069 | |||
| 1070 | /** |
||
| 1071 | * Duplicate name with a uniqid within name. |
||
| 1072 | */ |
||
| 1073 | protected function getDuplicateName(?string $name = null, ?string $class = null): string |
||
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Completly remove node. |
||
| 1099 | */ |
||
| 1100 | abstract protected function _forceDelete(): bool; |
||
| 1101 | } |
||
| 1102 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.