Complex classes like SoapClient 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 SoapClient, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class SoapClient extends \SoapClient implements SoapClientInterface |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var array |
||
| 19 | */ |
||
| 20 | protected $options; |
||
| 21 | /** |
||
| 22 | * @var EventDispatcherInterface |
||
| 23 | */ |
||
| 24 | protected $dispatcher; |
||
| 25 | /** |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | private $mockRequests = []; |
||
| 29 | /** |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | private $mockResponses = []; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * SoapClient constructor. |
||
| 36 | * @param null $wsdl |
||
| 37 | * @param array|null $options |
||
| 38 | */ |
||
| 39 | 18 | public function __construct($wsdl = null, array $options = []) |
|
| 74 | |||
| 75 | 6 | public function getOptions(): array |
|
| 79 | |||
| 80 | 9 | public function __call($function_name, $arguments) |
|
| 94 | |||
| 95 | public function __soapCall( |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @param string $request |
||
| 117 | * @param string $location |
||
| 118 | * @param string $action |
||
| 119 | * @param int $version |
||
| 120 | * @param null $one_way |
||
| 121 | * @return bool|string |
||
| 122 | */ |
||
| 123 | 6 | public function __doRequest($request, $location, $action, $version, $one_way = null) |
|
| 185 | |||
| 186 | /** |
||
| 187 | * Triggered before a request is executed |
||
| 188 | * |
||
| 189 | * @param string $id |
||
| 190 | * @param string $resource |
||
| 191 | * @param string $requestContent |
||
| 192 | */ |
||
| 193 | 6 | protected function preCall(string $id, string $resource, string $requestContent = null) |
|
| 199 | |||
| 200 | /** |
||
| 201 | * @param string $id |
||
| 202 | * @param string $resource |
||
| 203 | * @param string $response |
||
| 204 | */ |
||
| 205 | 6 | protected function postCall(string $id, string $resource, string $response = null) |
|
| 219 | |||
| 220 | /** |
||
| 221 | * @param string $id |
||
| 222 | * @param string $resource |
||
| 223 | * @param string $requestContent |
||
| 224 | * @param \Exception $exception |
||
| 225 | */ |
||
| 226 | 3 | protected function faultCall(string $id, string $resource, string $requestContent, \Exception $exception) |
|
| 235 | |||
| 236 | /** |
||
| 237 | * @param string $wsdl |
||
| 238 | * @return string |
||
| 239 | */ |
||
| 240 | 18 | protected function resolveLocation($wsdl) |
|
| 251 | |||
| 252 | /** |
||
| 253 | * @param array $mockRequests |
||
| 254 | */ |
||
| 255 | 12 | public function setMockRequests(array $mockRequests) |
|
| 259 | |||
| 260 | /** |
||
| 261 | * @param array $mockResponses |
||
| 262 | */ |
||
| 263 | 12 | public function setMockResponses(array $mockResponses) |
|
| 267 | |||
| 268 | /** |
||
| 269 | * @param EventDispatcherInterface $dispatcher |
||
| 270 | */ |
||
| 271 | 18 | public function setDispatcher(EventDispatcherInterface $dispatcher) |
|
| 275 | |||
| 276 | /** |
||
| 277 | * @param $function_name |
||
| 278 | * @param $arguments |
||
| 279 | * @param $e |
||
| 280 | */ |
||
| 281 | 3 | protected function handleFault($function_name, $arguments, $e): void |
|
| 292 | } |
||
| 293 |