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 |
||
| 22 | class PackageController extends CommonController |
||
| 23 | { |
||
| 24 | use \hiqdev\yii2\collection\ObjectTrait; |
||
| 25 | |||
| 26 | public function getType() |
||
| 30 | |||
| 31 | public function getLanguage() |
||
| 35 | |||
| 36 | public function getYears() |
||
| 47 | |||
| 48 | public function getYear() |
||
| 52 | |||
| 53 | public function getLicense() |
||
| 57 | |||
| 58 | public function getIssues() |
||
| 62 | |||
| 63 | public function getWiki() |
||
| 67 | |||
| 68 | public function getKeywords() |
||
| 72 | |||
| 73 | public function getFullName() |
||
| 77 | |||
| 78 | public function getSource() |
||
| 82 | |||
| 83 | public function getVersion() |
||
| 87 | |||
| 88 | public function getNamespace() |
||
| 92 | |||
| 93 | public static function defaultNamespace($vendor, $package) |
||
| 97 | |||
| 98 | public function getSrc() |
||
| 104 | |||
| 105 | public function getHomepage() |
||
| 109 | |||
| 110 | public function getForum() |
||
| 114 | |||
| 115 | public function getLabel() |
||
| 119 | |||
| 120 | public function isDomain() |
||
| 124 | |||
| 125 | public function getTitle() |
||
| 129 | |||
| 130 | public function getHeadline() |
||
| 134 | |||
| 135 | public function getDescription() |
||
| 139 | |||
| 140 | public function getRepositoryUrl($file) |
||
| 144 | |||
| 145 | public function getAuthors() |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Composer for the moment. |
||
| 152 | * To be changed to get actual Package Manager. |
||
| 153 | */ |
||
| 154 | public function getPackageManager() |
||
| 158 | |||
| 159 | public function hasRequireAny($package) |
||
| 163 | |||
| 164 | public function hasRequire($package) |
||
| 170 | |||
| 171 | public function hasRequireDev($package) |
||
| 177 | } |
||
| 178 |