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 |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Returns filesystem information by application, basename and path. |
||
| 96 | * |
||
| 97 | * @param int $applicationId |
||
| 98 | * @param string $path |
||
| 99 | * @param string $baseName |
||
| 100 | * @return null|FilesystemEntity |
||
| 101 | */ |
||
| 102 | public function getFilesystemByApplicationAndPath( |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Returns filesystem meta list identified by filesystem ID. |
||
| 124 | * |
||
| 125 | * @param int $identifier |
||
| 126 | * @param int $limit |
||
| 127 | * @param int $offset |
||
| 128 | * @return EntitySet |
||
| 129 | */ |
||
| 130 | public function getFilesystemMetaListByFilesystem( |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Returns a simplified form of the filesystem meta list. |
||
| 162 | * |
||
| 163 | * @param int $identifier |
||
| 164 | * @param int $limit |
||
| 165 | * @param int $offset |
||
| 166 | * @return null|array |
||
| 167 | */ |
||
| 168 | public function getSimpleFilesystemMetaListByFilesystem( |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Returns the full filesystem document data set. |
||
| 186 | * |
||
| 187 | * @param int $limit |
||
| 188 | * @param int $offset |
||
| 189 | * @return EntitySet |
||
| 190 | */ |
||
| 191 | public function getFilesystemDocumentList( |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Returns filesystem document information identified by (unique) ID. |
||
| 221 | * |
||
| 222 | * @param int $identifier |
||
| 223 | * @return null|FilesystemDocumentEntity |
||
| 224 | */ |
||
| 225 | public function getFilesystemDocumentById(int $identifier) : ? FilesystemDocumentEntity |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Returns published filesystem data along with the document data. |
||
| 240 | * |
||
| 241 | * @param int $applicationId |
||
| 242 | * @param string|null $order |
||
| 243 | * @param int $limit |
||
| 244 | * @param int $offset |
||
| 245 | * @return EntitySet |
||
| 246 | */ |
||
| 247 | public function getFilesystemPublishedDocumentList( |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Returns published filesystem data along with the document data. |
||
| 285 | * |
||
| 286 | * @param int $applicationId |
||
| 287 | * @param int $year |
||
| 288 | * @param int $month |
||
| 289 | * @param string|null $order |
||
| 290 | * @param int $limit |
||
| 291 | * @param int $offset |
||
| 292 | * @return EntitySet |
||
| 293 | */ |
||
| 294 | public function getFilesystemPublishedDocumentListByDate( |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Returns published filesystem data along with the document data. |
||
| 336 | * |
||
| 337 | * @param int $applicationId |
||
| 338 | * @param int $categoryId |
||
| 339 | * @param string|null $order |
||
| 340 | * @param int $limit |
||
| 341 | * @param int $offset |
||
| 342 | * @return EntitySet |
||
| 343 | */ |
||
| 344 | public function getFilesystemPublishedDocumentListByCategory( |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Returns published filesystem data according to a user ID along with the document data. |
||
| 384 | * |
||
| 385 | * @param int $applicationId |
||
| 386 | * @param int $userId |
||
| 387 | * @param string|null $order |
||
| 388 | * @param int $limit |
||
| 389 | * @param int $offset |
||
| 390 | * @return EntitySet |
||
| 391 | */ |
||
| 392 | public function getFilesystemPublishedDocumentListByAuthor( |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Returns published filesystem data according to a tag ID along with the document data. |
||
| 432 | * |
||
| 433 | * @param int $applicationId |
||
| 434 | * @param int $tagId |
||
| 435 | * @param string|null $order |
||
| 436 | * @param int $limit |
||
| 437 | * @param int $offset |
||
| 438 | * @return EntitySet |
||
| 439 | */ |
||
| 440 | public function getFilesystemPublishedDocumentListByTag( |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Returns filesystem information by application, basename and path. |
||
| 480 | * |
||
| 481 | * @param int $applicationId |
||
| 482 | * @param string $path |
||
| 483 | * @param string $baseName |
||
| 484 | * @return null|FilesystemPublishedDocumentEntity |
||
| 485 | */ |
||
| 486 | public function getFilesystemPublishedDocumentByApplicationAndPath( |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Returns a simplified list of publication dates. |
||
| 508 | * |
||
| 509 | * @param int $applicationId |
||
| 510 | * @param int $limit |
||
| 511 | * @param int $offset |
||
| 512 | * @return array |
||
| 513 | */ |
||
| 514 | public function getFilesystemPublishedDocumentDateList( |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Returns the tags for a filesystem record. |
||
| 533 | * |
||
| 534 | * @param int $filesystemId |
||
| 535 | * @param int $limit |
||
| 536 | * @param int $offset |
||
| 537 | * @return EntitySet |
||
| 538 | */ |
||
| 539 | public function getFilesystemTagListByFilesystem( |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Returns the tags for an application. |
||
| 571 | * |
||
| 572 | * @param int $applicationId |
||
| 573 | * @param int $limit |
||
| 574 | * @param int $offset |
||
| 575 | * @return EntitySet |
||
| 576 | */ |
||
| 577 | public function getFilesystemTagListByApplication( |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Returns filesystem tag information identified by (unique) ID. |
||
| 609 | * |
||
| 610 | * @param int $identifier |
||
| 611 | * @return null|FilesystemTagEntity |
||
| 612 | */ |
||
| 613 | public function getFilesystemTagById(int $identifier) : ? FilesystemTagEntity |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Returns filesystem tag information identified by (unique) ID. |
||
| 630 | * |
||
| 631 | * @param int $applicationId |
||
| 632 | * @param string $name |
||
| 633 | * @return null|FilesystemTagEntity |
||
| 634 | */ |
||
| 635 | public function getFilesystemTagByApplicationAndName( |
||
| 652 | |||
| 653 | /** |
||
| 654 | * Returns the categories for an application. |
||
| 655 | * |
||
| 656 | * @param int $applicationId |
||
| 657 | * @param int $limit |
||
| 658 | * @param int $offset |
||
| 659 | * @return EntitySet |
||
| 660 | */ |
||
| 661 | public function getFilesystemCategoryListByApplication( |
||
| 690 | |||
| 691 | /** |
||
| 692 | * Returns filesystem category information identified by (unique) ID. |
||
| 693 | * |
||
| 694 | * @param int $identifier |
||
| 695 | * @return null|FilesystemCategoryEntity |
||
| 696 | */ |
||
| 697 | public function getFilesystemCategoryById(int $identifier) : ? FilesystemCategoryEntity |
||
| 711 | |||
| 712 | /** |
||
| 713 | * Returns filesystem category information identified by application ID and category name. |
||
| 714 | * |
||
| 715 | * @param int $applicationId |
||
| 716 | * @param string $categoryName |
||
| 717 | * @return null|FilesystemCategoryEntity |
||
| 718 | */ |
||
| 719 | public function getFilesystemCategoryByApplicationAndName( |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Returns filesystem directory information identified by (unique) ID. |
||
| 739 | * |
||
| 740 | * @param int $identifier |
||
| 741 | * @return null|FilesystemDirectoryEntity |
||
| 742 | */ |
||
| 743 | public function getFilesystemDirectoryById(int $identifier) : ? FilesystemDirectoryEntity |
||
| 757 | |||
| 758 | /** |
||
| 759 | * Returns filesystem directory information identified by its proxy. |
||
| 760 | * |
||
| 761 | * @param string $proxy |
||
| 762 | * @return null|FilesystemDirectoryEntity |
||
| 763 | */ |
||
| 764 | public function getFilesystemDirectoryByProxy(string $proxy) : ? FilesystemDirectoryEntity |
||
| 778 | |||
| 779 | /** |
||
| 780 | * Returns a combined information of the filesystem and directory according to the application and the proxy. |
||
| 781 | * |
||
| 782 | * @param int $applicationId |
||
| 783 | * @param string $proxy |
||
| 784 | * @return null|FilesystemDirectoryDataEntity |
||
| 785 | */ |
||
| 786 | public function getFilesystemDirectoryDataByApplicationAndProxy( |
||
| 803 | } |
||
| 804 |
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.