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 |
||
| 21 | abstract class AbstractClient implements ClientInterface |
||
| 22 | { |
||
| 23 | protected $host; |
||
| 24 | protected $port; |
||
| 25 | protected $username; |
||
| 26 | protected $password; |
||
| 27 | protected $services; |
||
| 28 | protected $serviceExtensions; |
||
| 29 | protected $ssl; |
||
| 30 | protected $local_cert; |
||
| 31 | protected $ca_cert; |
||
| 32 | protected $pk_cert; |
||
| 33 | protected $passphrase; |
||
| 34 | protected $debug; |
||
| 35 | protected $connect_timeout; |
||
| 36 | protected $timeout; |
||
| 37 | protected $objectSpec; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * {@inheritdoc} |
||
| 41 | * |
||
| 42 | * @see \AfriCC\EPP\ClientInterface::connect() |
||
| 43 | */ |
||
| 44 | abstract public function connect($newPassword = false); |
||
| 45 | |||
| 46 | abstract public function close(); |
||
| 47 | |||
| 48 | abstract protected function log($message); |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Send frame to EPP server |
||
| 52 | * |
||
| 53 | * @param FrameInterface $frame Frame to send |
||
| 54 | * |
||
| 55 | * @throws Exception on send error |
||
| 56 | */ |
||
| 57 | abstract public function sendFrame(FrameInterface $frame); |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Get response frame from EPP server (use after sendFrame) |
||
| 61 | * |
||
| 62 | * @throws Exception on frame receive error |
||
| 63 | * |
||
| 64 | * @return string raw XML of EPP Frame |
||
| 65 | */ |
||
| 66 | abstract public function getFrame(); |
||
| 67 | |||
| 68 | public function request(FrameInterface $frame) |
||
| 82 | |||
| 83 | public function __construct(array $config, ObjectSpec $objectSpec = null) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Get client's ObjectSpec |
||
| 105 | * |
||
| 106 | * @return ObjectSpec |
||
| 107 | */ |
||
| 108 | public function getObjectSpec() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Set client's ObjectSpec |
||
| 115 | * |
||
| 116 | * @param ObjectSpec $newObjectSpec |
||
| 117 | */ |
||
| 118 | public function setObjectSpec(ObjectSpec $newObjectSpec) |
||
| 122 | |||
| 123 | protected function prepareConnectionOptions(array $config) |
||
| 147 | |||
| 148 | protected function prepareCredentials(array $config) |
||
| 158 | |||
| 159 | protected function prepareSSLOptions(array $config) |
||
| 195 | |||
| 196 | protected function prepareEPPServices(array $config) |
||
| 206 | |||
| 207 | protected function generateClientTransactionId() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Generate and send login frame |
||
| 214 | * |
||
| 215 | * @param bool|string $newPassword New password to set on login, false if not changing password |
||
| 216 | * |
||
| 217 | * @throws \Exception On unsuccessful login |
||
| 218 | * |
||
| 219 | * @return \AfriCC\EPP\Frame\Response Login response |
||
| 220 | */ |
||
| 221 | protected function login($newPassword = false) |
||
| 257 | } |
||
| 258 |