Complex classes like FilesystemStorage 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 FilesystemStorage, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | class FilesystemStorage extends AbstractStorage |
||
33 | { |
||
34 | /** |
||
35 | * Returns a set of filesystem data accroding to the application and directory ID. |
||
36 | * |
||
37 | * @param int $applicationId |
||
38 | * @param int $directoryId |
||
39 | * @param int $limit |
||
40 | * @param int $offset |
||
41 | * @return EntitySet |
||
42 | */ |
||
43 | public function getFilesystemListByApplicationAndDirectory( |
||
74 | |||
75 | /** |
||
76 | * Returns filesystem information identified by (unique) ID. |
||
77 | * |
||
78 | * @param int $identifier |
||
79 | * @return null|FilesystemEntity |
||
80 | */ |
||
81 | public function getFilesystemById(int $identifier) : ? FilesystemEntity |
||
95 | |||
96 | /** |
||
97 | * Returns filesystem information by application, basename and path. |
||
98 | * |
||
99 | * @param int $applicationId |
||
100 | * @param string $path |
||
101 | * @param string $baseName |
||
102 | * @return null|FilesystemEntity |
||
103 | */ |
||
104 | public function getFilesystemByApplicationAndPath( |
||
125 | |||
126 | /** |
||
127 | * Returns filesystem meta list identified by filesystem ID. |
||
128 | * |
||
129 | * @param int $identifier |
||
130 | * @param int $limit |
||
131 | * @param int $offset |
||
132 | * @return EntitySet |
||
133 | */ |
||
134 | public function getFilesystemMetaListByFilesystem( |
||
163 | |||
164 | /** |
||
165 | * Returns a simplified form of the filesystem meta list. |
||
166 | * |
||
167 | * @param int $identifier |
||
168 | * @param int $limit |
||
169 | * @param int $offset |
||
170 | * @return null|array |
||
171 | */ |
||
172 | public function getSimpleFilesystemMetaListByFilesystem( |
||
187 | |||
188 | /** |
||
189 | * Returns the full filesystem document data set. |
||
190 | * |
||
191 | * @param int $limit |
||
192 | * @param int $offset |
||
193 | * @return EntitySet |
||
194 | */ |
||
195 | public function getFilesystemDocumentList( |
||
222 | |||
223 | /** |
||
224 | * Returns filesystem document information identified by (unique) ID. |
||
225 | * |
||
226 | * @param int $identifier |
||
227 | * @return null|FilesystemDocumentEntity |
||
228 | */ |
||
229 | public function getFilesystemDocumentById(int $identifier) : ? FilesystemDocumentEntity |
||
243 | |||
244 | /** |
||
245 | * Returns published filesystem data along with the document data. |
||
246 | * |
||
247 | * @param int $applicationId |
||
248 | * @param string|null $order |
||
249 | * @param int $limit |
||
250 | * @param int $offset |
||
251 | * @return EntitySet |
||
252 | */ |
||
253 | public function getFilesystemPublishedDocumentList( |
||
288 | |||
289 | /** |
||
290 | * Returns published filesystem data along with the document data. |
||
291 | * |
||
292 | * @param int $applicationId |
||
293 | * @param int $year |
||
294 | * @param int $month |
||
295 | * @param string|null $order |
||
296 | * @param int $limit |
||
297 | * @param int $offset |
||
298 | * @return EntitySet |
||
299 | */ |
||
300 | public function getFilesystemPublishedDocumentListByDate( |
||
339 | |||
340 | /** |
||
341 | * Returns published filesystem data along with the document data. |
||
342 | * |
||
343 | * @param int $applicationId |
||
344 | * @param int $categoryId |
||
345 | * @param string|null $order |
||
346 | * @param int $limit |
||
347 | * @param int $offset |
||
348 | * @return EntitySet |
||
349 | */ |
||
350 | public function getFilesystemPublishedDocumentListByCategory( |
||
387 | |||
388 | /** |
||
389 | * Returns published filesystem data according to a user ID along with the document data. |
||
390 | * |
||
391 | * @param int $applicationId |
||
392 | * @param int $userId |
||
393 | * @param string|null $order |
||
394 | * @param int $limit |
||
395 | * @param int $offset |
||
396 | * @return EntitySet |
||
397 | */ |
||
398 | public function getFilesystemPublishedDocumentListByAuthor( |
||
435 | |||
436 | /** |
||
437 | * Returns published filesystem data according to a tag ID along with the document data. |
||
438 | * |
||
439 | * @param int $applicationId |
||
440 | * @param int $tagId |
||
441 | * @param string|null $order |
||
442 | * @param int $limit |
||
443 | * @param int $offset |
||
444 | * @return EntitySet |
||
445 | */ |
||
446 | public function getFilesystemPublishedDocumentListByTag( |
||
483 | |||
484 | /** |
||
485 | * Returns filesystem information by application, basename and path. |
||
486 | * |
||
487 | * @param int $applicationId |
||
488 | * @param string $path |
||
489 | * @param string $baseName |
||
490 | * @return null|FilesystemPublishedDocumentEntity |
||
491 | */ |
||
492 | public function getFilesystemPublishedDocumentByApplicationAndPath( |
||
513 | |||
514 | /** |
||
515 | * Returns a simplified list of publication dates. |
||
516 | * |
||
517 | * @param int $applicationId |
||
518 | * @param int $limit |
||
519 | * @param int $offset |
||
520 | * @return array |
||
521 | */ |
||
522 | public function getFilesystemPublishedDocumentDateList( |
||
538 | |||
539 | /** |
||
540 | * Returns the tags for a filesystem record. |
||
541 | * |
||
542 | * @param int $filesystemId |
||
543 | * @param int $limit |
||
544 | * @param int $offset |
||
545 | * @return EntitySet |
||
546 | */ |
||
547 | public function getFilesystemTagListByFilesystem( |
||
576 | |||
577 | /** |
||
578 | * Returns the tags for an application. |
||
579 | * |
||
580 | * @param int $applicationId |
||
581 | * @param int $limit |
||
582 | * @param int $offset |
||
583 | * @return EntitySet |
||
584 | */ |
||
585 | public function getFilesystemTagListByApplication( |
||
614 | |||
615 | /** |
||
616 | * Returns filesystem tag information identified by (unique) ID. |
||
617 | * |
||
618 | * @param int $identifier |
||
619 | * @return null|FilesystemTagEntity |
||
620 | */ |
||
621 | public function getFilesystemTagById(int $identifier) : ? FilesystemTagEntity |
||
637 | |||
638 | /** |
||
639 | * Returns filesystem tag information identified by (unique) ID. |
||
640 | * |
||
641 | * @param int $applicationId |
||
642 | * @param string $name |
||
643 | * @return null|FilesystemTagEntity |
||
644 | */ |
||
645 | public function getFilesystemTagByApplicationAndName( |
||
664 | |||
665 | /** |
||
666 | * Returns the categories for an application. |
||
667 | * |
||
668 | * @param int $applicationId |
||
669 | * @param int $limit |
||
670 | * @param int $offset |
||
671 | * @return EntitySet |
||
672 | */ |
||
673 | public function getFilesystemCategoryListByApplication( |
||
702 | |||
703 | /** |
||
704 | * Returns filesystem category information identified by (unique) ID. |
||
705 | * |
||
706 | * @param int $identifier |
||
707 | * @return null|FilesystemCategoryEntity |
||
708 | */ |
||
709 | public function getFilesystemCategoryById(int $identifier) : ? FilesystemCategoryEntity |
||
725 | |||
726 | /** |
||
727 | * Returns filesystem category information identified by application ID and category name. |
||
728 | * |
||
729 | * @param int $applicationId |
||
730 | * @param string $categoryName |
||
731 | * @return null|FilesystemCategoryEntity |
||
732 | */ |
||
733 | public function getFilesystemCategoryByApplicationAndName( |
||
752 | |||
753 | /** |
||
754 | * Returns filesystem directory information identified by (unique) ID. |
||
755 | * |
||
756 | * @param int $identifier |
||
757 | * @return null|FilesystemDirectoryEntity |
||
758 | */ |
||
759 | public function getFilesystemDirectoryById(int $identifier) : ? FilesystemDirectoryEntity |
||
775 | |||
776 | /** |
||
777 | * Returns filesystem directory information identified by its proxy. |
||
778 | * |
||
779 | * @param string $proxy |
||
780 | * @return null|FilesystemDirectoryEntity |
||
781 | */ |
||
782 | public function getFilesystemDirectoryByProxy(string $proxy) : ? FilesystemDirectoryEntity |
||
798 | |||
799 | /** |
||
800 | * Returns a combined information of the filesystem and directory according to the application and the proxy. |
||
801 | * |
||
802 | * @param int $applicationId |
||
803 | * @param string $proxy |
||
804 | * @return null|FilesystemDirectoryDataEntity |
||
805 | */ |
||
806 | public function getFilesystemDirectoryDataByApplicationAndProxy( |
||
825 | } |
||
826 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.