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 getLicense() |
||
| 35 | |||
| 36 | public function getIssues() |
||
| 40 | |||
| 41 | public function getWiki() |
||
| 45 | |||
| 46 | public function getKeywords() |
||
| 50 | |||
| 51 | public function getFullName() |
||
| 55 | |||
| 56 | public function getSource() |
||
| 60 | |||
| 61 | public function getNamespace() |
||
| 65 | |||
| 66 | public static function defaultNamespace($vendor, $package) |
||
| 70 | |||
| 71 | public function getSrc() |
||
| 75 | |||
| 76 | public function getHomepage() |
||
| 80 | |||
| 81 | public function getForum() |
||
| 85 | |||
| 86 | public function getLabel() |
||
| 90 | |||
| 91 | public function getTitle() |
||
| 95 | |||
| 96 | public function getHeadline() |
||
| 100 | |||
| 101 | public function getDescription() |
||
| 105 | |||
| 106 | public function getRepositoryUrl($file) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Composer for the moment. |
||
| 117 | * To be changed to get actual Package Manager. |
||
| 118 | */ |
||
| 119 | public function getPackageManager() |
||
| 123 | |||
| 124 | public function hasRequireAny($package) |
||
| 128 | |||
| 129 | public function hasRequire($package) |
||
| 134 | |||
| 135 | public function hasRequireDev($package) |
||
| 140 | } |
||
| 141 |
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@propertyannotation 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.