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 | * Storage adapter. |
||
| 192 | * |
||
| 193 | * @var string |
||
| 194 | */ |
||
| 195 | protected $storage_adapter; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Acl. |
||
| 199 | * |
||
| 200 | * @var Acl |
||
| 201 | */ |
||
| 202 | protected $acl; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Storage. |
||
| 206 | * |
||
| 207 | * @var Storage |
||
| 208 | */ |
||
| 209 | protected $_storage; |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Convert to filename. |
||
| 213 | * |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function __toString() |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Get owner. |
||
| 223 | */ |
||
| 224 | public function getOwner(): ObjectId |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Set filesystem. |
||
| 231 | */ |
||
| 232 | public function setFilesystem(Filesystem $fs): NodeInterface |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Get filesystem. |
||
| 242 | */ |
||
| 243 | public function getFilesystem(): Filesystem |
||
| 247 | |||
| 248 | /** |
||
| 249 | * temporary session. |
||
| 250 | */ |
||
| 251 | public function temporarySession($stream, ObjectId $session = null): ObjectId |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Check if $node is a sub node of any parent nodes of this node. |
||
| 258 | */ |
||
| 259 | public function isSubNode(NodeInterface $node): bool |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Move node. |
||
| 280 | */ |
||
| 281 | public function setParent(Collection $parent, int $conflict = NodeInterface::CONFLICT_NOACTION): NodeInterface |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Get share id. |
||
| 362 | * |
||
| 363 | * |
||
| 364 | * @return ObjectId |
||
| 365 | */ |
||
| 366 | public function getShareId(bool $reference = false): ?ObjectId |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Get share node. |
||
| 389 | * |
||
| 390 | * @return Collection |
||
| 391 | */ |
||
| 392 | public function getShareNode(): ?Collection |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Is node marked as readonly? |
||
| 407 | */ |
||
| 408 | public function isReadonly(): bool |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Request is from node owner? |
||
| 415 | */ |
||
| 416 | public function isOwnerRequest(): bool |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Check if node is kind of special. |
||
| 423 | */ |
||
| 424 | public function isSpecial(): bool |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Check if node is a sub node of a share. |
||
| 441 | */ |
||
| 442 | public function isShareMember(): bool |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Is share. |
||
| 449 | */ |
||
| 450 | public function isShare(): bool |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Is share (Reference or master share). |
||
| 457 | */ |
||
| 458 | public function isShared(): bool |
||
| 466 | |||
| 467 | /** |
||
| 468 | * Set the name. |
||
| 469 | * |
||
| 470 | * @param string $name |
||
| 471 | */ |
||
| 472 | public function setName($name): bool |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Check name. |
||
| 495 | */ |
||
| 496 | public function checkName(string $name): string |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Get the name. |
||
| 514 | */ |
||
| 515 | public function getName(): string |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Undelete. |
||
| 522 | * |
||
| 523 | * @param string $recursion |
||
| 524 | */ |
||
| 525 | public function undelete(int $conflict = NodeInterface::CONFLICT_NOACTION, ?string $recursion = null, bool $recursion_first = true): bool |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Is node deleted? |
||
| 611 | */ |
||
| 612 | public function isDeleted(): bool |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Get last modified timestamp. |
||
| 619 | */ |
||
| 620 | public function getLastModified(): int |
||
| 628 | |||
| 629 | /** |
||
| 630 | * Get unique id. |
||
| 631 | * |
||
| 632 | * @return ObjectId |
||
| 633 | */ |
||
| 634 | 1 | public function getId(): ?ObjectId |
|
| 638 | |||
| 639 | /** |
||
| 640 | * Get parent. |
||
| 641 | * |
||
| 642 | * @return Collection |
||
| 643 | */ |
||
| 644 | public function getParent(): ?Collection |
||
| 674 | |||
| 675 | /** |
||
| 676 | * Get parents. |
||
| 677 | */ |
||
| 678 | public function getParents(?NodeInterface $node = null, array $parents = []): array |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Get as zip. |
||
| 695 | */ |
||
| 696 | public function getZip(): void |
||
| 702 | |||
| 703 | /** |
||
| 704 | * Create zip. |
||
| 705 | * |
||
| 706 | * @param bool $self true means that the zip represents the collection itself instead a child of the zip |
||
| 707 | * @param NodeInterface $parent |
||
| 708 | */ |
||
| 709 | public function zip(ZipStream $archive, bool $self = true, ?NodeInterface $parent = null, string $path = '', int $depth = 0): bool |
||
| 754 | |||
| 755 | /** |
||
| 756 | * Get mime type. |
||
| 757 | */ |
||
| 758 | 1 | public function getContentType(): string |
|
| 762 | |||
| 763 | /** |
||
| 764 | * Is reference. |
||
| 765 | */ |
||
| 766 | public function isReference(): bool |
||
| 770 | |||
| 771 | /** |
||
| 772 | * Set app attributes. |
||
| 773 | */ |
||
| 774 | public function setAppAttributes(string $namespace, array $attributes): NodeInterface |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Set app attribute. |
||
| 784 | */ |
||
| 785 | public function setAppAttribute(string $namespace, string $attribute, $value): NodeInterface |
||
| 796 | |||
| 797 | /** |
||
| 798 | * Remove app attribute. |
||
| 799 | */ |
||
| 800 | public function unsetAppAttributes(string $namespace): NodeInterface |
||
| 809 | |||
| 810 | /** |
||
| 811 | * Remove app attribute. |
||
| 812 | */ |
||
| 813 | public function unsetAppAttribute(string $namespace, string $attribute): NodeInterface |
||
| 822 | |||
| 823 | /** |
||
| 824 | * Get app attribute. |
||
| 825 | */ |
||
| 826 | public function getAppAttribute(string $namespace, string $attribute) |
||
| 834 | |||
| 835 | /** |
||
| 836 | * Get app attributes. |
||
| 837 | */ |
||
| 838 | public function getAppAttributes(string $namespace): array |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Set meta attributes. |
||
| 849 | */ |
||
| 850 | public function setMetaAttributes(array $attributes): NodeInterface |
||
| 865 | |||
| 866 | /** |
||
| 867 | * Get meta attributes as array. |
||
| 868 | */ |
||
| 869 | public function getMetaAttributes(array $attributes = []): array |
||
| 878 | |||
| 879 | /** |
||
| 880 | * Mark node as readonly. |
||
| 881 | */ |
||
| 882 | public function setReadonly(bool $readonly = true): bool |
||
| 888 | |||
| 889 | /** |
||
| 890 | * Mark node as self-destroyable. |
||
| 891 | * |
||
| 892 | * @param UTCDateTime $ts |
||
| 893 | */ |
||
| 894 | public function setDestroyable(?UTCDateTime $ts): bool |
||
| 904 | |||
| 905 | /** |
||
| 906 | * Get original raw attributes before any processing. |
||
| 907 | */ |
||
| 908 | public function getRawAttributes(): array |
||
| 912 | |||
| 913 | /** |
||
| 914 | * Check if node is in root. |
||
| 915 | */ |
||
| 916 | public function isInRoot(): bool |
||
| 920 | |||
| 921 | /** |
||
| 922 | * Check if node is an instance of the actual root collection. |
||
| 923 | */ |
||
| 924 | public function isRoot(): bool |
||
| 928 | |||
| 929 | /** |
||
| 930 | * Resolve node path. |
||
| 931 | */ |
||
| 932 | public function getPath(): string |
||
| 943 | |||
| 944 | /** |
||
| 945 | * Save node attributes. |
||
| 946 | * |
||
| 947 | * @param array|string $attributes |
||
| 948 | * @param array|string $remove |
||
| 949 | * @param string $recursion |
||
| 950 | */ |
||
| 951 | public function save($attributes = [], $remove = [], ?string $recursion = null, bool $recursion_first = true): bool |
||
| 1015 | |||
| 1016 | /** |
||
| 1017 | * Get array value via string path. |
||
| 1018 | */ |
||
| 1019 | protected function getArrayValue(Iterable $array, string $path, string $separator = '.') |
||
| 1036 | |||
| 1037 | /** |
||
| 1038 | * Validate meta attributes. |
||
| 1039 | */ |
||
| 1040 | protected function validateMetaAttributes(array $attributes): array |
||
| 1059 | |||
| 1060 | /** |
||
| 1061 | * Duplicate name with a uniqid within name. |
||
| 1062 | */ |
||
| 1063 | protected function getDuplicateName(?string $name = null, ?string $class = null): string |
||
| 1086 | |||
| 1087 | /** |
||
| 1088 | * Completly remove node. |
||
| 1089 | */ |
||
| 1090 | abstract protected function _forceDelete(): bool; |
||
| 1091 | } |
||
| 1092 |
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.