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 | * @return void Doesn't return! |
||
| 55 | * @throws Exception on send error |
||
| 56 | */ |
||
| 57 | abstract protected function sendFrame(FrameInterface $frame); |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Get response frame from EPP server (use after sendFrame) |
||
| 61 | * |
||
| 62 | * @return string raw XML of EPP Frame |
||
| 63 | * @throws Exception on frame receive error |
||
| 64 | */ |
||
| 65 | abstract protected function getFrame(); |
||
| 66 | |||
| 67 | public function request(FrameInterface $frame) |
||
| 81 | |||
| 82 | public function __construct(array $config, ObjectSpec $objectSpec = null) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Get client's ObjectSpec |
||
| 104 | * |
||
| 105 | * @return ObjectSpec |
||
| 106 | */ |
||
| 107 | public function getObjectSpec() |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Set client's ObjectSpec |
||
| 114 | * |
||
| 115 | * @param ObjectSpec $newObjectSpec |
||
| 116 | */ |
||
| 117 | public function setObjectSpec(ObjectSpec $newObjectSpec) |
||
| 121 | |||
| 122 | protected function prepareConnectionOptions(array $config) |
||
| 146 | |||
| 147 | protected function prepareCredentials(array $config) |
||
| 157 | |||
| 158 | protected function prepareSSLOptions(array $config) |
||
| 194 | |||
| 195 | protected function prepareEPPServices(array $config) |
||
| 205 | |||
| 206 | protected function generateClientTransactionId() |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Generate and send login frame |
||
| 213 | * |
||
| 214 | * @param bool|string $newPassword New password to set on login, false if not changing password |
||
| 215 | * |
||
| 216 | * @throws \Exception On unsuccessful login |
||
| 217 | * |
||
| 218 | * @return \AfriCC\EPP\Frame\Response Login response |
||
| 219 | */ |
||
| 220 | protected function login($newPassword = false) |
||
| 256 | } |
||
| 257 |