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 |
||
| 21 | class NginxController extends \hidev\controllers\CommonController |
||
| 22 | { |
||
| 23 | use \hiqdev\yii2\collection\ManagerTrait; |
||
| 24 | |||
| 25 | protected $_logDir; |
||
| 26 | protected $_etcDir; |
||
| 27 | protected $_fpmSocket; |
||
| 28 | |||
| 29 | public $defaultClass = VhostController::class; |
||
| 30 | |||
| 31 | 1 | public function actionDoDump() |
|
| 38 | |||
| 39 | 1 | public function actionDump() |
|
| 43 | |||
| 44 | public function actionDeploy($aliases = []) |
||
| 48 | |||
| 49 | public function actionDoDeploy() |
||
| 68 | |||
| 69 | public function actionStart() |
||
| 73 | |||
| 74 | public function actionStop() |
||
| 78 | |||
| 79 | public function actionReload() |
||
| 83 | |||
| 84 | public function actionRestart() |
||
| 88 | |||
| 89 | public function actionStatus() |
||
| 93 | |||
| 94 | public function make($operation, $sudo = true) |
||
| 103 | |||
| 104 | public function actionMake() |
||
| 108 | |||
| 109 | public function actionLetsencrypt() |
||
| 113 | |||
| 114 | public function actionDoLetsencrypt() |
||
| 132 | |||
| 133 | public function actionChmodSsl() |
||
| 139 | |||
| 140 | public static function mkdir($path) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Prepares item config. |
||
| 151 | */ |
||
| 152 | 1 | public function getItemConfig($name = null, array $config = []) |
|
| 160 | |||
| 161 | 1 | public function createItem($id, $config = []) |
|
| 165 | |||
| 166 | public function setLogDir($value) |
||
| 170 | |||
| 171 | 1 | public function getLogDir() |
|
| 179 | |||
| 180 | public function setEtcDir($value) |
||
| 184 | |||
| 185 | public function getEtcDir() |
||
| 193 | |||
| 194 | public function findEtcDir() |
||
| 205 | |||
| 206 | 1 | public function setFpmSocket($value) |
|
| 210 | |||
| 211 | 1 | public function getFpmSocket() |
|
| 219 | |||
| 220 | public function findFpmSocketFile() |
||
| 231 | } |
||
| 232 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.