Complex classes like CurlSoapClient 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 CurlSoapClient, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class CurlSoapClient extends SoapClient |
||
| 19 | { |
||
| 20 | protected $curl = null; ///< cURL handle |
||
| 21 | protected $redirect_max; ///< max redirect counts |
||
| 22 | protected $curl_timeout; ///< cURL request time-out seconds |
||
| 23 | private $redirect_count = 0; |
||
| 24 | private $proxy_type = null; |
||
| 25 | |||
| 26 | 13 | public function __construct($wsdl, array $options) |
|
| 43 | |||
| 44 | 13 | public function __destruct() |
|
| 50 | |||
| 51 | 1 | public function ___curlSetOpt($option, $value) |
|
| 55 | |||
| 56 | 1 | public function __getCookies() |
|
| 60 | |||
| 61 | 1 | public function __setCookie($name, $value = null) |
|
| 69 | |||
| 70 | /** |
||
| 71 | * Execute SOAP requests. |
||
| 72 | * |
||
| 73 | * @param string $request SOAP request |
||
| 74 | * @param string $location SOAP address |
||
| 75 | * @param string $action SOAP action |
||
| 76 | * @param int $version SOAP version |
||
| 77 | * @param int $one_way |
||
| 78 | * @throws \Exception |
||
| 79 | * @throws \SoapFault |
||
| 80 | * @return string|object (string) SOAP response / (object) SoapFault object |
||
| 81 | */ |
||
| 82 | 13 | public function __doRequest($request, $location, $action, $version, $one_way = 0) |
|
| 129 | |||
| 130 | /** |
||
| 131 | * set CURLOPT_HTTPHEADER. |
||
| 132 | * |
||
| 133 | * @param string $action SOAP action |
||
| 134 | * @param int $version SOAP version |
||
| 135 | */ |
||
| 136 | 13 | private function ___configHeader($action, $version) |
|
| 152 | |||
| 153 | /** |
||
| 154 | * set CURLOPT_ENCODING. |
||
| 155 | */ |
||
| 156 | 13 | private function ___configCompression() |
|
| 169 | |||
| 170 | /** |
||
| 171 | * set CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT. |
||
| 172 | */ |
||
| 173 | 13 | private function ___configTimeout() |
|
| 182 | |||
| 183 | /** |
||
| 184 | * set CURLOPT_USERPWD and CURLOPT_HTTPAUTH. |
||
| 185 | */ |
||
| 186 | 13 | private function ___configHttpAuthentication() |
|
| 198 | |||
| 199 | /** |
||
| 200 | * set proxy options. |
||
| 201 | */ |
||
| 202 | 13 | private function ___configProxy() |
|
| 203 | { |
||
| 204 | 13 | if ($this->___isEmptyExtProperty('_proxy_host')) { |
|
| 205 | 12 | return; |
|
| 206 | } |
||
| 207 | 1 | curl_setopt($this->curl, CURLOPT_PROXY, $this->_proxy_host); |
|
| 208 | 1 | if (!$this->___isEmptyExtProperty('_proxy_port')) { |
|
| 209 | 1 | curl_setopt($this->curl, CURLOPT_PROXYPORT, $this->_proxy_port); |
|
| 210 | } |
||
| 211 | |||
| 212 | 1 | if (!$this->___isEmptyExtProperty('_proxy_login') && !$this->___isEmptyExtProperty('_proxy_password')) { |
|
| 213 | 1 | curl_setopt($this->curl, CURLOPT_PROXYUSERPWD, $this->_proxy_login . ':' . $this->_proxy_password); |
|
| 214 | } |
||
| 215 | 1 | curl_setopt($this->curl, CURLOPT_PROXYUSERPWD, $this->_proxy_login . ':' . $this->_proxy_password); |
|
| 216 | 1 | if (property_exists($this, '_digest')) { |
|
| 217 | curl_setopt($this->curl, CURLOPT_PROXYAUTH, CURLAUTH_ANYSAFE); |
||
| 218 | } else { |
||
| 219 | 1 | curl_setopt($this->curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY); |
|
| 220 | } |
||
| 221 | 1 | if ($this->proxy_type == 'socks5') { |
|
| 222 | curl_setopt($this->curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); |
||
| 223 | 1 | } elseif ($this->proxy_type == 'socks4') { |
|
| 224 | curl_setopt($this->curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4); |
||
| 225 | 1 | } elseif ($this->proxy_type == 'http') { |
|
| 226 | // @see http://stackoverflow.com/questions/12288956/what-is-the-curl-option-curlopt-httpproxytunnel-means |
||
| 227 | curl_setopt($this->curl, CURLOPT_HTTPPROXYTUNNEL, true); |
||
| 228 | } |
||
| 229 | 1 | } |
|
| 230 | |||
| 231 | /** |
||
| 232 | * Request cURL. |
||
| 233 | * |
||
| 234 | * @param string $location SOAP address |
||
| 235 | * @param string $location |
||
| 236 | * @throws \SoapFault |
||
| 237 | * @return mixed response body |
||
| 238 | */ |
||
| 239 | 13 | private function ___curlCall($location) |
|
| 299 | |||
| 300 | /** |
||
| 301 | * check body is XML or not |
||
| 302 | * |
||
| 303 | * @param string $response_body server response body |
||
| 304 | * @return boolean |
||
| 305 | */ |
||
| 306 | 4 | private function ___isErrorResponse($response_body) { |
|
| 325 | |||
| 326 | |||
| 327 | /** |
||
| 328 | * SoapClient property util |
||
| 329 | * |
||
| 330 | * @param string $property property name |
||
| 331 | * @return boolean |
||
| 332 | */ |
||
| 333 | 13 | private function ___isEmptyExtProperty($property) |
|
| 344 | } |
||
| 345 |