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 |
||
| 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 | 9 | public function __construct($wsdl = null, array $options = []) |
|
| 74 | |||
| 75 | 9 | public function __call($function_name, $arguments) |
|
| 89 | |||
| 90 | public function __soapCall( |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @param string $request |
||
| 112 | * @param string $location |
||
| 113 | * @param string $action |
||
| 114 | * @param int $version |
||
| 115 | * @param null $one_way |
||
| 116 | * @return bool|string |
||
| 117 | */ |
||
| 118 | 6 | public function __doRequest($request, $location, $action, $version, $one_way = null) |
|
| 180 | |||
| 181 | /** |
||
| 182 | * Triggered before a request is executed |
||
| 183 | * |
||
| 184 | * @param string $id |
||
| 185 | * @param string $resource |
||
| 186 | * @param string $requestContent |
||
| 187 | */ |
||
| 188 | 6 | protected function preCall(string $id, string $resource, string $requestContent = null) |
|
| 194 | |||
| 195 | /** |
||
| 196 | * @param string $id |
||
| 197 | * @param string $resource |
||
| 198 | * @param string $response |
||
| 199 | */ |
||
| 200 | 6 | protected function postCall(string $id, string $resource, string $response = null) |
|
| 214 | |||
| 215 | /** |
||
| 216 | * @param string $id |
||
| 217 | * @param string $resource |
||
| 218 | * @param string $requestContent |
||
| 219 | * @param \Exception $exception |
||
| 220 | */ |
||
| 221 | 3 | protected function faultCall(string $id, string $resource, string $requestContent, \Exception $exception) |
|
| 230 | |||
| 231 | /** |
||
| 232 | * @param string $wsdl |
||
| 233 | * @return string |
||
| 234 | */ |
||
| 235 | 9 | protected function resolveLocation($wsdl) |
|
| 246 | |||
| 247 | /** |
||
| 248 | * @param array $mockRequests |
||
| 249 | */ |
||
| 250 | 9 | public function setMockRequests(array $mockRequests) |
|
| 254 | |||
| 255 | /** |
||
| 256 | * @param array $mockResponses |
||
| 257 | */ |
||
| 258 | 9 | public function setMockResponses(array $mockResponses) |
|
| 262 | |||
| 263 | /** |
||
| 264 | * @param EventDispatcherInterface $dispatcher |
||
| 265 | */ |
||
| 266 | 9 | public function setDispatcher(EventDispatcherInterface $dispatcher) |
|
| 270 | |||
| 271 | /** |
||
| 272 | * @param $function_name |
||
| 273 | * @param $arguments |
||
| 274 | * @param $e |
||
| 275 | */ |
||
| 276 | 3 | protected function handleFault($function_name, $arguments, $e): void |
|
| 287 | } |
||
| 288 |