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 |
||
387 | |||
388 | /** |
||
389 | * Set node acl. |
||
390 | */ |
||
391 | public function setAcl(array $acl): NodeInterface |
||
410 | |||
411 | /** |
||
412 | * Get ACL. |
||
413 | */ |
||
414 | public function getAcl(): array |
||
424 | |||
425 | /** |
||
426 | * Get share id. |
||
427 | */ |
||
428 | public function getShareId(bool $reference = false): ?ObjectId |
||
448 | |||
449 | /** |
||
450 | * Get reference. |
||
451 | */ |
||
452 | public function getReference(): ?ObjectId |
||
456 | |||
457 | /** |
||
458 | * Get share node. |
||
459 | */ |
||
460 | public function getShareNode(): ?Collection |
||
472 | |||
473 | /** |
||
474 | * Is node marked as readonly? |
||
475 | */ |
||
476 | public function isReadonly(): bool |
||
480 | |||
481 | /** |
||
482 | * Request is from node owner? |
||
483 | */ |
||
484 | public function isOwnerRequest(): bool |
||
488 | |||
489 | /** |
||
490 | * Check if node is kind of special. |
||
491 | */ |
||
492 | public function isSpecial(): bool |
||
506 | |||
507 | /** |
||
508 | * Check if node is a sub node of a share. |
||
509 | */ |
||
510 | public function isShareMember(): bool |
||
514 | |||
515 | /** |
||
516 | * Check if node is a sub node of an external storage mount. |
||
517 | */ |
||
518 | public function isMountMember(): bool |
||
522 | |||
523 | /** |
||
524 | * Is share. |
||
525 | */ |
||
526 | public function isShare(): bool |
||
530 | |||
531 | /** |
||
532 | * Is share (Reference or master share). |
||
533 | */ |
||
534 | public function isShared(): bool |
||
542 | |||
543 | /** |
||
544 | * Set the name. |
||
545 | */ |
||
546 | public function setName($name): bool |
||
571 | |||
572 | /** |
||
573 | * Check name. |
||
574 | */ |
||
575 | public function checkName(string $name): string |
||
590 | |||
591 | /** |
||
592 | * Get the name. |
||
593 | */ |
||
594 | public function getName(): string |
||
598 | |||
599 | /** |
||
600 | * Get mount node. |
||
601 | */ |
||
602 | public function getMount(): ?ObjectId |
||
606 | |||
607 | /** |
||
608 | * Undelete. |
||
609 | */ |
||
610 | public function undelete(int $conflict = NodeInterface::CONFLICT_NOACTION, ?string $recursion = null, bool $recursion_first = true): bool |
||
669 | |||
670 | /** |
||
671 | * Is node deleted? |
||
672 | */ |
||
673 | public function isDeleted(): bool |
||
677 | |||
678 | /** |
||
679 | * Get last modified timestamp. |
||
680 | */ |
||
681 | public function getLastModified(): int |
||
689 | |||
690 | /** |
||
691 | * Get unique id. |
||
692 | */ |
||
693 | 1 | public function getId(): ?ObjectId |
|
697 | |||
698 | /** |
||
699 | * Get parent. |
||
700 | */ |
||
701 | public function getParent(): ?Collection |
||
705 | |||
706 | /** |
||
707 | * Get parents. |
||
708 | */ |
||
709 | public function getParents(?NodeInterface $node = null, array $parents = []): array |
||
723 | |||
724 | /** |
||
725 | * Get as zip. |
||
726 | */ |
||
727 | public function getZip(): void |
||
733 | |||
734 | /** |
||
735 | * Create zip. |
||
736 | */ |
||
737 | public function zip(ZipStream $archive, bool $self = true, ?NodeInterface $parent = null, string $path = '', int $depth = 0): bool |
||
782 | |||
783 | /** |
||
784 | * Get mime type. |
||
785 | */ |
||
786 | 1 | public function getContentType(): string |
|
790 | |||
791 | /** |
||
792 | * Is reference. |
||
793 | */ |
||
794 | public function isReference(): bool |
||
798 | |||
799 | /** |
||
800 | * Set app attributes. |
||
801 | */ |
||
802 | public function setAppAttributes(string $namespace, array $attributes): NodeInterface |
||
809 | |||
810 | /** |
||
811 | * Set app attribute. |
||
812 | */ |
||
813 | public function setAppAttribute(string $namespace, string $attribute, $value): NodeInterface |
||
824 | |||
825 | /** |
||
826 | * Remove app attribute. |
||
827 | */ |
||
828 | public function unsetAppAttributes(string $namespace): NodeInterface |
||
837 | |||
838 | /** |
||
839 | * Remove app attribute. |
||
840 | */ |
||
841 | public function unsetAppAttribute(string $namespace, string $attribute): NodeInterface |
||
850 | |||
851 | /** |
||
852 | * Get app attribute. |
||
853 | */ |
||
854 | public function getAppAttribute(string $namespace, string $attribute) |
||
862 | |||
863 | /** |
||
864 | * Get app attributes. |
||
865 | */ |
||
866 | public function getAppAttributes(string $namespace): array |
||
874 | |||
875 | /** |
||
876 | * Set meta attributes. |
||
877 | */ |
||
878 | public function setMetaAttributes(array $attributes): NodeInterface |
||
893 | |||
894 | /** |
||
895 | * Get meta attributes as array. |
||
896 | */ |
||
897 | public function getMetaAttributes(array $attributes = []): array |
||
906 | |||
907 | /** |
||
908 | * Mark node as readonly. |
||
909 | */ |
||
910 | public function setReadonly(bool $readonly = true): bool |
||
917 | |||
918 | /** |
||
919 | * Mark node as self-destroyable. |
||
920 | */ |
||
921 | public function setDestroyable(?UTCDateTime $ts): bool |
||
931 | |||
932 | /** |
||
933 | * Get original raw attributes before any processing. |
||
934 | */ |
||
935 | public function getRawAttributes(): array |
||
939 | |||
940 | /** |
||
941 | * Check if node is in root. |
||
942 | */ |
||
943 | public function isInRoot(): bool |
||
947 | |||
948 | /** |
||
949 | * Check if node is an instance of the actual root collection. |
||
950 | */ |
||
951 | public function isRoot(): bool |
||
955 | |||
956 | /** |
||
957 | * Resolve node path. |
||
958 | */ |
||
959 | public function getPath(): string |
||
970 | |||
971 | /** |
||
972 | * Save node attributes. |
||
973 | * |
||
974 | * @param array|string $attributes |
||
975 | * @param array|string $remove |
||
976 | * @param string $recursion |
||
977 | */ |
||
978 | public function save($attributes = [], $remove = [], ?string $recursion = null, bool $recursion_first = true): bool |
||
1042 | |||
1043 | /** |
||
1044 | * Get array value via string path. |
||
1045 | */ |
||
1046 | protected function getArrayValue(iterable $array, string $path, string $separator = '.') |
||
1063 | |||
1064 | /** |
||
1065 | * Validate meta attributes. |
||
1066 | */ |
||
1067 | protected function validateMetaAttributes(array $attributes): array |
||
1086 | |||
1087 | /** |
||
1088 | * Duplicate name with a uniqid within name. |
||
1089 | */ |
||
1090 | protected function getDuplicateName(?string $name = null, ?string $class = null): string |
||
1113 | |||
1114 | /** |
||
1115 | * Completly remove node. |
||
1116 | */ |
||
1117 | abstract protected function _forceDelete(): bool; |
||
1118 | } |
||
1119 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.