Complex classes like FilesystemEntity 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 FilesystemEntity, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class FilesystemEntity extends AbstractEntity |
||
22 | { |
||
23 | public const TYPE_DOCUMENT = 'document'; |
||
24 | public const TYPE_BINARY = 'binary'; |
||
25 | public const TYPE_DIRECTORY = 'directory'; |
||
26 | public const TYPE_SYMLINK = 'symlink'; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $container = [ |
||
32 | 'id_filesystem' => null, |
||
33 | 'fk_application' => null, |
||
34 | 'fk_category' => null, |
||
35 | 'fk_parent_node' => null, |
||
36 | 'fk_filesystem_document' => null, |
||
37 | 'fk_filesystem_file' => null, |
||
38 | 'fk_filesystem_directory' => null, |
||
39 | 'fk_filesystem_link' => null, |
||
40 | 'path' => null, |
||
41 | 'basename' => null, |
||
42 | 'uri' => null, |
||
43 | 'title' => null, |
||
44 | 'description' => null, |
||
45 | 'is_hidden' => null, |
||
46 | 'is_read_only' => null, |
||
47 | 'is_deleted' => null, |
||
48 | 'date_created' => null, |
||
49 | 'date_modified' => null, |
||
50 | 'date_published' => null, |
||
51 | ]; |
||
52 | |||
53 | /** |
||
54 | * @return null|string |
||
55 | */ |
||
56 | public function getType() : ? string |
||
69 | |||
70 | /** |
||
71 | * @param int $identifier |
||
72 | * @return FilesystemEntity |
||
73 | */ |
||
74 | public function setFilesystemId(int $identifier) : FilesystemEntity |
||
80 | |||
81 | /** |
||
82 | * @return int|null |
||
83 | */ |
||
84 | public function getFilesystemId() : ? int |
||
90 | |||
91 | /** |
||
92 | * @param int $applicationIdentifier |
||
93 | * @return FilesystemEntity |
||
94 | */ |
||
95 | public function setApplicationId(int $applicationIdentifier) : FilesystemEntity |
||
101 | |||
102 | /** |
||
103 | * @return int|null |
||
104 | */ |
||
105 | public function getApplicationId() : ? int |
||
111 | |||
112 | /** |
||
113 | * @param int $categoryIdentifier |
||
114 | * @return FilesystemEntity |
||
115 | */ |
||
116 | public function setCategoryId(int $categoryIdentifier) : FilesystemEntity |
||
122 | |||
123 | /** |
||
124 | * @return int|null |
||
125 | */ |
||
126 | public function getCategoryId() : ? int |
||
132 | |||
133 | /** |
||
134 | * @param int $parentNodeIdentifier |
||
135 | * @return FilesystemEntity |
||
136 | */ |
||
137 | public function setParentNodeId(int $parentNodeIdentifier) : FilesystemEntity |
||
143 | |||
144 | /** |
||
145 | * @return int|null |
||
146 | */ |
||
147 | public function getParentNodeId() : ? int |
||
153 | |||
154 | /** |
||
155 | * @param int $documentIdentifier |
||
156 | * @return FilesystemEntity |
||
157 | */ |
||
158 | public function setFilesystemDocumentId(int $documentIdentifier) : FilesystemEntity |
||
164 | |||
165 | /** |
||
166 | * @return int|null |
||
167 | */ |
||
168 | public function getFilesystemDocumentId() : ? int |
||
174 | |||
175 | /** |
||
176 | * @param int $fileIdentifier |
||
177 | * @return FilesystemEntity |
||
178 | */ |
||
179 | public function setFilesystemFileId(int $fileIdentifier) : FilesystemEntity |
||
185 | |||
186 | /** |
||
187 | * @return int|null |
||
188 | */ |
||
189 | public function getFilesystemFileId() : ? int |
||
195 | |||
196 | /** |
||
197 | * @param int $directoryIdentifier |
||
198 | * @return FilesystemEntity |
||
199 | */ |
||
200 | public function setFilesystemDirectoryId(int $directoryIdentifier) : FilesystemEntity |
||
206 | |||
207 | /** |
||
208 | * @return int|null |
||
209 | */ |
||
210 | public function getFilesystemDirectoryId() : ? int |
||
216 | |||
217 | /** |
||
218 | * @param int $linkIdentifier |
||
219 | * @return FilesystemEntity |
||
220 | */ |
||
221 | public function setFilesystemLinkId(int $linkIdentifier) : FilesystemEntity |
||
227 | |||
228 | /** |
||
229 | * @return int|null |
||
230 | */ |
||
231 | public function getFilesystemLinkId() : ? int |
||
237 | |||
238 | /** |
||
239 | * @param string $path |
||
240 | * @return FilesystemEntity |
||
241 | */ |
||
242 | public function setPath(string $path) : FilesystemEntity |
||
248 | |||
249 | /** |
||
250 | * @return null|string |
||
251 | */ |
||
252 | public function getPath() : ? string |
||
256 | |||
257 | /** |
||
258 | * @param string $baseName |
||
259 | * @return FilesystemEntity |
||
260 | */ |
||
261 | public function setBaseName(string $baseName) : FilesystemEntity |
||
267 | |||
268 | /** |
||
269 | * @return null|string |
||
270 | */ |
||
271 | public function getBaseName() : ? string |
||
275 | |||
276 | /** |
||
277 | * @param string $uri |
||
278 | * @return FilesystemEntity |
||
279 | */ |
||
280 | public function setUri(string $uri) : FilesystemEntity |
||
286 | |||
287 | /** |
||
288 | * @return null|string |
||
289 | */ |
||
290 | public function getUri() : ? string |
||
294 | |||
295 | /** |
||
296 | * @param string $title |
||
297 | * @return FilesystemEntity |
||
298 | */ |
||
299 | public function setTitle(string $title) : FilesystemEntity |
||
305 | |||
306 | /** |
||
307 | * @return null|string |
||
308 | */ |
||
309 | public function getTitle() : ? string |
||
313 | |||
314 | /** |
||
315 | * @param string $description |
||
316 | * @return FilesystemEntity |
||
317 | */ |
||
318 | public function setDescription(string $description) : FilesystemEntity |
||
324 | |||
325 | /** |
||
326 | * @return null|string |
||
327 | */ |
||
328 | public function getDescription() : ? string |
||
332 | |||
333 | /** |
||
334 | * @param bool $isHidden |
||
335 | * @return FilesystemEntity |
||
336 | */ |
||
337 | public function setIsHidden(bool $isHidden) : FilesystemEntity |
||
343 | |||
344 | /** |
||
345 | * @return bool |
||
346 | */ |
||
347 | public function getIsHidden() : bool |
||
351 | |||
352 | /** |
||
353 | * @param bool $isReadonly |
||
354 | * @return FilesystemEntity |
||
355 | */ |
||
356 | public function setIsReadOnly(bool $isReadonly) : FilesystemEntity |
||
362 | |||
363 | /** |
||
364 | * @return bool |
||
365 | */ |
||
366 | public function getIsReadOnly() : bool |
||
370 | |||
371 | /** |
||
372 | * @param bool $isDeleted |
||
373 | * @return FilesystemEntity |
||
374 | */ |
||
375 | public function setIsDeleted(bool $isDeleted) : FilesystemEntity |
||
381 | |||
382 | /** |
||
383 | * @return bool |
||
384 | */ |
||
385 | public function getIsDeleted() : bool |
||
389 | |||
390 | /** |
||
391 | * @param DateTime $dateTime |
||
392 | * @return FilesystemEntity |
||
393 | */ |
||
394 | public function setDateCreated(DateTime $dateTime) : FilesystemEntity |
||
400 | |||
401 | /** |
||
402 | * @return null|DateTime |
||
403 | */ |
||
404 | public function getDateCreated() : ? DateTime |
||
410 | |||
411 | /** |
||
412 | * @param DateTime $dateTime |
||
413 | * @return FilesystemEntity |
||
414 | */ |
||
415 | public function setDateModified(DateTime $dateTime) : FilesystemEntity |
||
421 | |||
422 | /** |
||
423 | * @return null|DateTime |
||
424 | */ |
||
425 | public function getDateModified() : ? DateTime |
||
431 | |||
432 | /** |
||
433 | * @param DateTime $dateTime |
||
434 | * @return FilesystemEntity |
||
435 | */ |
||
436 | public function setDatePublished(DateTime $dateTime) : FilesystemEntity |
||
442 | |||
443 | /** |
||
444 | * @return null|DateTime |
||
445 | */ |
||
446 | public function getDatePublished() : ? DateTime |
||
452 | } |
||
453 |