Complex classes like Vhost 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 Vhost, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class Vhost extends \hidev\base\Component |
||
21 | { |
||
22 | /** |
||
23 | * @var Nginx |
||
24 | */ |
||
25 | public $nginx; |
||
26 | |||
27 | /** |
||
28 | * @var integer |
||
29 | */ |
||
30 | public $timeout; |
||
31 | |||
32 | public $ssl; |
||
33 | |||
34 | public $_aliases = []; |
||
35 | |||
36 | protected $_sslDir; |
||
37 | protected $_ips = []; |
||
38 | protected $_localIps = []; |
||
39 | protected $_domain; |
||
40 | protected $_webDir; |
||
41 | protected $_logDir; |
||
42 | protected $_phpLogDir; |
||
43 | protected $_fpmSocket; |
||
44 | protected $_additionalConfig; |
||
45 | |||
46 | public function chmodSSL() |
||
53 | |||
54 | public function renderConf() |
||
60 | |||
61 | public function setDomain($value) |
||
65 | |||
66 | public function setDomains($domains) |
||
74 | |||
75 | public function getDomain() |
||
83 | |||
84 | public function setIp($value) |
||
88 | |||
89 | public function setIps($value) |
||
93 | |||
94 | public function getIps() |
||
102 | |||
103 | public function findIps() |
||
112 | |||
113 | public function setLocalIps($value) |
||
117 | |||
118 | public function getLocalIps() |
||
126 | |||
127 | public function setWebDir($value) |
||
131 | |||
132 | public function getWebDir() |
||
140 | |||
141 | public function setPhpLogDir($value) |
||
145 | |||
146 | public function getPhpLogDir() |
||
158 | |||
159 | public function setLogDir($value) |
||
163 | |||
164 | public function getLogDir() |
||
172 | |||
173 | public function setFpmSocket($value) |
||
177 | |||
178 | public function getFpmSocket() |
||
186 | |||
187 | public function setSslDir($value) |
||
194 | |||
195 | public function getSslDir() |
||
203 | |||
204 | public function setAliases($aliases) |
||
211 | |||
212 | public function getAliases() |
||
216 | |||
217 | public function getDomains() |
||
224 | |||
225 | public function getServerName() |
||
229 | |||
230 | public function getAdditionalConfig() |
||
234 | |||
235 | public function setAdditionalConfig($additinalConfig) |
||
239 | } |
||
240 |