Complex classes like NginxController 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 NginxController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | class NginxController extends \hidev\controllers\CommonController |
||
23 | { |
||
24 | use \hiqdev\yii2\collection\ManagerTrait; |
||
25 | |||
26 | protected $_logDir; |
||
27 | protected $_etcDir; |
||
28 | protected $_fpmSocket; |
||
29 | |||
30 | public $defaultClass = VhostController::class; |
||
31 | 1 | ||
32 | public function actionDoDump() |
||
39 | 1 | ||
40 | public function actionDump() |
||
44 | |||
45 | public function actionDeploy($aliases = []) |
||
49 | |||
50 | public function actionDoDeploy() |
||
69 | |||
70 | public function actionStart() |
||
74 | |||
75 | public function actionStop() |
||
79 | |||
80 | public function actionReload() |
||
84 | |||
85 | public function actionRestart() |
||
89 | |||
90 | public function actionStatus() |
||
94 | |||
95 | public function make($operation, $sudo = true) |
||
104 | |||
105 | public function actionMake() |
||
109 | |||
110 | public function actionLetsencrypt() |
||
114 | |||
115 | public function actionDoLetsencrypt() |
||
133 | |||
134 | public function actionChmodSsl() |
||
140 | |||
141 | public static function mkdir($path) |
||
149 | |||
150 | /** |
||
151 | * Prepares item config. |
||
152 | 1 | */ |
|
153 | public function getItemConfig($name = null, array $config = []) |
||
161 | 1 | ||
162 | public function createItem($id, $config = []) |
||
166 | |||
167 | public function setLogDir($value) |
||
171 | 1 | ||
172 | public function getLogDir() |
||
180 | |||
181 | public function setEtcDir($value) |
||
185 | |||
186 | public function getEtcDir() |
||
194 | |||
195 | public function findEtcDir() |
||
206 | 1 | ||
207 | public function setFpmSocket($value) |
||
211 | 1 | ||
212 | public function getFpmSocket() |
||
220 | |||
221 | public function findFpmSocketFile() |
||
232 | } |
||
233 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.