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 getLanguage() |
||
| 36 | |||
| 37 | 2 | public function getYears() |
|
| 48 | |||
| 49 | public function getYear() |
||
| 53 | |||
| 54 | public function getLicense() |
||
| 58 | |||
| 59 | public function getIssues() |
||
| 63 | |||
| 64 | public function getWiki() |
||
| 68 | |||
| 69 | public function getKeywords() |
||
| 73 | |||
| 74 | public function getFullName() |
||
| 78 | |||
| 79 | public function getSource() |
||
| 83 | |||
| 84 | public function getVersion() |
||
| 88 | |||
| 89 | public function getNamespace() |
||
| 93 | |||
| 94 | public static function defaultNamespace($vendor, $package) |
||
| 98 | |||
| 99 | public function getSrc() |
||
| 105 | |||
| 106 | public function getHomepage() |
||
| 110 | |||
| 111 | public function getForum() |
||
| 115 | |||
| 116 | public function getLabel() |
||
| 120 | |||
| 121 | public function isDomain() |
||
| 125 | |||
| 126 | public function getTitle() |
||
| 130 | |||
| 131 | public function getHeadline() |
||
| 135 | |||
| 136 | public function getDescription() |
||
| 140 | |||
| 141 | public function getRepositoryUrl($file) |
||
| 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 |