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 | |||
| 32 | public function actionDump() |
||
| 39 | |||
| 40 | public function actionDeploy($aliases = []) |
||
| 44 | |||
| 45 | public function actionDoDeploy() |
||
| 64 | |||
| 65 | public function actionStart() |
||
| 69 | |||
| 70 | public function actionStop() |
||
| 74 | |||
| 75 | public function actionReload() |
||
| 79 | |||
| 80 | public function actionRestart() |
||
| 84 | |||
| 85 | public function actionStatus() |
||
| 89 | |||
| 90 | public function make($operation, $sudo = true) |
||
| 99 | |||
| 100 | public function actionMake() |
||
| 104 | |||
| 105 | public function actionLetsencrypt() |
||
| 109 | |||
| 110 | public function actionDoLetsencrypt() |
||
| 128 | |||
| 129 | public function actionChmodSsl() |
||
| 135 | |||
| 136 | public static function mkdir($path) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Prepares item config. |
||
| 147 | */ |
||
| 148 | public function getItemConfig($name = null, array $config = []) |
||
| 156 | |||
| 157 | public function createItem($id, $config = []) |
||
| 161 | |||
| 162 | public function setLogDir($value) |
||
| 166 | |||
| 167 | public function getLogDir() |
||
| 175 | |||
| 176 | public function setEtcDir($value) |
||
| 180 | |||
| 181 | public function getEtcDir() |
||
| 189 | |||
| 190 | public function findEtcDir() |
||
| 201 | |||
| 202 | public function setFpmSocket($value) |
||
| 206 | |||
| 207 | public function getFpmSocket() |
||
| 215 | |||
| 216 | public function findFpmSocketFile() |
||
| 227 | } |
||
| 228 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.