Complex classes like AbstractClient 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 AbstractClient, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | abstract class AbstractClient implements ClientInterface, LoggerAwareInterface |
||
24 | { |
||
25 | use LoggerAwareTrait; |
||
26 | |||
27 | protected $host; |
||
28 | protected $port; |
||
29 | protected $username; |
||
30 | protected $password; |
||
31 | protected $services; |
||
32 | protected $serviceExtensions; |
||
33 | protected $ssl; |
||
34 | protected $local_cert; |
||
35 | protected $ca_cert; |
||
36 | protected $pk_cert; |
||
37 | protected $passphrase; |
||
38 | protected $debug; |
||
39 | protected $connect_timeout; |
||
40 | protected $timeout; |
||
41 | protected $objectSpec; |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | * |
||
46 | * @see \AfriCC\EPP\ClientInterface::connect() |
||
47 | */ |
||
48 | abstract public function connect($newPassword = false); |
||
49 | |||
50 | abstract public function close(); |
||
51 | |||
52 | /** |
||
53 | * Prints out debugging data (eg raw frame bytes) |
||
54 | * |
||
55 | * @param string $message |
||
56 | */ |
||
57 | abstract protected function debugLog($message); |
||
58 | |||
59 | protected function logCommand(FrameInterface $frame) |
||
67 | |||
68 | /** |
||
69 | * @param ResponseFrame|string $frame |
||
70 | */ |
||
71 | protected function logResponse($frame) |
||
79 | |||
80 | /** |
||
81 | * Send frame to EPP server |
||
82 | * |
||
83 | * @param FrameInterface $frame Frame to send |
||
84 | * |
||
85 | * @throws Exception on send error |
||
86 | */ |
||
87 | abstract public function sendFrame(FrameInterface $frame); |
||
88 | |||
89 | /** |
||
90 | * Get response frame from EPP server (use after sendFrame) |
||
91 | * |
||
92 | * @throws Exception on frame receive error |
||
93 | * |
||
94 | * @return string raw XML of EPP Frame |
||
95 | */ |
||
96 | abstract public function getFrame(); |
||
97 | |||
98 | public function request(FrameInterface $frame) |
||
115 | |||
116 | public function __construct(array $config, ObjectSpec $objectSpec = null) |
||
135 | |||
136 | /** |
||
137 | * Get client's ObjectSpec |
||
138 | * |
||
139 | * @return ObjectSpec |
||
140 | */ |
||
141 | public function getObjectSpec() |
||
145 | |||
146 | /** |
||
147 | * Set client's ObjectSpec |
||
148 | * |
||
149 | * @param ObjectSpec $newObjectSpec |
||
150 | */ |
||
151 | public function setObjectSpec(ObjectSpec $newObjectSpec) |
||
155 | |||
156 | protected function prepareConnectionOptions(array $config) |
||
180 | |||
181 | protected function prepareCredentials(array $config) |
||
191 | |||
192 | protected function prepareSSLOptions(array $config) |
||
228 | |||
229 | protected function prepareEPPServices(array $config) |
||
239 | |||
240 | protected function generateClientTransactionId() |
||
244 | |||
245 | /** |
||
246 | * Generate and send login frame |
||
247 | * |
||
248 | * @param bool|string $newPassword New password to set on login, false if not changing password |
||
249 | * |
||
250 | * @throws \Exception On unsuccessful login |
||
251 | * |
||
252 | * @return \AfriCC\EPP\Frame\Response Login response |
||
253 | */ |
||
254 | protected function login($newPassword = false) |
||
290 | } |
||
291 |