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 |
||
19 | class PackageController extends CommonController |
||
20 | { |
||
21 | use \hiqdev\yii2\collection\ObjectTrait; |
||
22 | |||
23 | public function getYears() |
||
30 | |||
31 | public function getYear() |
||
35 | |||
36 | public function getLicense() |
||
40 | |||
41 | public function getIssues() |
||
45 | |||
46 | public function getWiki() |
||
50 | |||
51 | public function getKeywords() |
||
55 | |||
56 | public function getFullName() |
||
60 | |||
61 | public function getSource() |
||
65 | |||
66 | public function getNamespace() |
||
70 | |||
71 | public static function defaultNamespace($vendor, $package) |
||
75 | |||
76 | public function getSrc() |
||
80 | |||
81 | public function getHomepage() |
||
85 | |||
86 | public function getForum() |
||
90 | |||
91 | public function getLabel() |
||
95 | |||
96 | public function getTitle() |
||
100 | |||
101 | public function getHeadline() |
||
105 | |||
106 | public function getDescription() |
||
110 | |||
111 | public function getRepositoryUrl($file) |
||
119 | |||
120 | /** |
||
121 | * Composer for the moment. |
||
122 | * To be changed to get actual Package Manager. |
||
123 | */ |
||
124 | public function getPackageManager() |
||
128 | |||
129 | public function hasRequireAny($package) |
||
133 | |||
134 | public function hasRequire($package) |
||
139 | |||
140 | public function hasRequireDev($package) |
||
145 | } |
||
146 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.