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 | 2 | public function getYears() |
|
43 | |||
44 | public function getYear() |
||
48 | |||
49 | public function getLicense() |
||
53 | |||
54 | public function getIssues() |
||
58 | |||
59 | public function getWiki() |
||
63 | |||
64 | public function getKeywords() |
||
68 | |||
69 | public function getFullName() |
||
73 | |||
74 | public function getSource() |
||
78 | |||
79 | public function getVersion() |
||
83 | |||
84 | public function getNamespace() |
||
88 | |||
89 | public static function defaultNamespace($vendor, $package) |
||
93 | |||
94 | public function getSrc() |
||
100 | |||
101 | public function getHomepage() |
||
105 | |||
106 | public function getForum() |
||
110 | |||
111 | public function getLabel() |
||
115 | |||
116 | public function isDomain() |
||
120 | |||
121 | public function getTitle() |
||
125 | |||
126 | public function getHeadline() |
||
130 | |||
131 | public function getDescription() |
||
135 | |||
136 | public function getRepositoryUrl($file) |
||
144 | |||
145 | /** |
||
146 | * Composer for the moment. |
||
147 | * To be changed to get actual Package Manager. |
||
148 | */ |
||
149 | public function getPackageManager() |
||
153 | |||
154 | public function hasRequireAny($package) |
||
158 | |||
159 | public function hasRequire($package) |
||
165 | |||
166 | public function hasRequireDev($package) |
||
172 | } |
||
173 |