Complex classes like PackageController 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 PackageController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class PackageController extends CommonController |
||
| 24 | { |
||
| 25 | use \hiqdev\yii2\collection\ObjectTrait; |
||
| 26 | |||
| 27 | public function getType() |
||
| 31 | |||
| 32 | public function getYears() |
||
| 39 | |||
| 40 | public function getYear() |
||
| 44 | |||
| 45 | public function getLicense() |
||
| 49 | |||
| 50 | public function getIssues() |
||
| 54 | |||
| 55 | public function getWiki() |
||
| 59 | |||
| 60 | public function getKeywords() |
||
| 64 | |||
| 65 | public function getFullName() |
||
| 69 | |||
| 70 | public function getSource() |
||
| 74 | |||
| 75 | public function getVersion() |
||
| 79 | |||
| 80 | public function getNamespace() |
||
| 84 | |||
| 85 | public static function defaultNamespace($vendor, $package) |
||
| 89 | |||
| 90 | public function getSrc() |
||
| 96 | |||
| 97 | public function getHomepage() |
||
| 101 | |||
| 102 | public function getForum() |
||
| 106 | |||
| 107 | public function getLabel() |
||
| 111 | |||
| 112 | public function isDomain() |
||
| 116 | |||
| 117 | public function getTitle() |
||
| 121 | |||
| 122 | public function getHeadline() |
||
| 126 | |||
| 127 | public function getDescription() |
||
| 131 | |||
| 132 | public function getRepositoryUrl($file) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Composer for the moment. |
||
| 143 | * To be changed to get actual Package Manager. |
||
| 144 | */ |
||
| 145 | public function getPackageManager() |
||
| 149 | |||
| 150 | public function hasRequireAny($package) |
||
| 154 | |||
| 155 | public function hasRequire($package) |
||
| 161 | |||
| 162 | public function hasRequireDev($package) |
||
| 168 | } |
||
| 169 |