Complex classes like Domrobot 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 Domrobot, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class Domrobot |
||
16 | { |
||
17 | private $debug = false; |
||
18 | private $address; |
||
19 | private $language; |
||
20 | private $customer = ""; |
||
21 | private $clTRID = null; |
||
22 | |||
23 | private $_ver = "2.4"; |
||
24 | private $_cachedir; |
||
25 | private $_cookiefile = NULL; |
||
26 | private $loginResult = NULL; |
||
27 | |||
28 | /** |
||
29 | * Domrobot constructor. |
||
30 | * @param $address |
||
31 | * @param string $locale |
||
32 | * @param $cache_dir |
||
33 | * @param $username |
||
34 | * @param $password |
||
35 | * @param null $sharedSecret |
||
36 | */ |
||
37 | public function __construct($address, $locale = 'en', $cache_dir, $username, $password, $sharedSecret = null) |
||
45 | |||
46 | /** |
||
47 | * @param string $name |
||
48 | * @param $ip |
||
49 | * @param string $domain |
||
50 | * @param string $type |
||
51 | * @return mixed|string |
||
52 | */ |
||
53 | public function createRecord($name, $ip, $domain = 'somedomainnameyouwishtoupgrade.de', $type = 'A') |
||
70 | |||
71 | /** |
||
72 | * @param integer $id |
||
73 | * @param $ip |
||
74 | * @return mixed |
||
75 | */ |
||
76 | public function updateRecord($id, $ip) |
||
84 | |||
85 | /** |
||
86 | * @param integer $id |
||
87 | * @param bool $testing |
||
88 | * @return mixed |
||
89 | */ |
||
90 | public function deleteRecord($id, $testing = false) |
||
98 | |||
99 | /** |
||
100 | * @param $username |
||
101 | * @param $password |
||
102 | * @param null $sharedSecret |
||
103 | * @return mixed |
||
104 | */ |
||
105 | public function login($username, $password, $sharedSecret = null) |
||
132 | |||
133 | /** |
||
134 | * @param string $object |
||
135 | * @param string $method |
||
136 | * @param array $params |
||
137 | * @return mixed |
||
138 | */ |
||
139 | public function call($object, $method, array $params = array()) |
||
173 | |||
174 | /** |
||
175 | * @param $secret |
||
176 | * @return string |
||
177 | */ |
||
178 | private function _getSecretCode($secret) |
||
202 | |||
203 | /** |
||
204 | * @param $secret |
||
205 | * @return string|false |
||
206 | */ |
||
207 | private function _base32Decode($secret) |
||
248 | |||
249 | /** |
||
250 | * @return string[] |
||
251 | */ |
||
252 | private function _getBase32LookupTable() |
||
262 | |||
263 | /** |
||
264 | * logout on destruct |
||
265 | */ |
||
266 | public function __destruct() |
||
270 | |||
271 | /** |
||
272 | * @return mixed |
||
273 | */ |
||
274 | public function logout() |
||
282 | |||
283 | /** |
||
284 | * @return string |
||
285 | */ |
||
286 | public function getLanguage() |
||
290 | |||
291 | /** |
||
292 | * @param string $language |
||
293 | */ |
||
294 | public function setLanguage($language) |
||
298 | |||
299 | /** |
||
300 | * @return bool |
||
301 | */ |
||
302 | public function getDebug() |
||
306 | |||
307 | /** |
||
308 | * @param bool $debug |
||
309 | */ |
||
310 | public function setDebug($debug = false) |
||
314 | |||
315 | /** |
||
316 | * @return string |
||
317 | */ |
||
318 | public function getCookiefile() |
||
322 | |||
323 | /** |
||
324 | * @param $file |
||
325 | * @throws \Exception |
||
326 | */ |
||
327 | public function setCookiefile($file) |
||
334 | |||
335 | /** |
||
336 | * @return string |
||
337 | */ |
||
338 | public function getCustomer() |
||
342 | |||
343 | /** |
||
344 | * @param $customer |
||
345 | */ |
||
346 | public function setCustomer($customer) |
||
350 | |||
351 | /** |
||
352 | * @return string |
||
353 | */ |
||
354 | public function getClTrId() |
||
358 | |||
359 | /** |
||
360 | * @param $clTrId |
||
361 | */ |
||
362 | public function setClTrId($clTrId) |
||
366 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: