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 |
||
17 | class SoapClient extends \SoapClient implements SoapClientInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $options; |
||
23 | /** |
||
24 | * @var EventDispatcherInterface |
||
25 | */ |
||
26 | protected $dispatcher; |
||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $mockRequests = []; |
||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | private $mockResponses = []; |
||
35 | |||
36 | /** |
||
37 | * SoapClient constructor. |
||
38 | * @param null $wsdl |
||
39 | * @param array|null $options |
||
40 | */ |
||
41 | 12 | public function __construct($wsdl = null, array $options = []) |
|
76 | |||
77 | 4 | public function getOptions(): array |
|
81 | |||
82 | 6 | public function __call($function_name, $arguments) |
|
96 | |||
97 | public function __soapCall( |
||
116 | |||
117 | /** |
||
118 | * @param string $request |
||
119 | * @param string $location |
||
120 | * @param string $action |
||
121 | * @param int $version |
||
122 | * @param null $one_way |
||
123 | * @return bool|string |
||
124 | */ |
||
125 | 4 | public function __doRequest($request, $location, $action, $version, $one_way = null) |
|
187 | |||
188 | /** |
||
189 | * Triggered before a request is executed |
||
190 | * |
||
191 | * @param string $id |
||
192 | * @param string $resource |
||
193 | * @param string $requestContent |
||
194 | */ |
||
195 | 4 | 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 | 4 | protected function postCall(string $id, string $resource, string $response = null) |
|
217 | |||
218 | /** |
||
219 | * @param string $id |
||
220 | * @param string $resource |
||
221 | * @param string $requestContent |
||
222 | * @param \Exception $exception |
||
223 | */ |
||
224 | 2 | protected function faultCall(string $id, string $resource, string $requestContent, \Exception $exception) |
|
231 | |||
232 | /** |
||
233 | * @param string $wsdl |
||
234 | * @return string |
||
235 | */ |
||
236 | 12 | protected function resolveLocation($wsdl) |
|
247 | |||
248 | /** |
||
249 | * @param array $mockRequests |
||
250 | */ |
||
251 | 8 | public function setMockRequests(array $mockRequests) |
|
255 | |||
256 | /** |
||
257 | * @param array $mockResponses |
||
258 | */ |
||
259 | 8 | public function setMockResponses(array $mockResponses) |
|
263 | |||
264 | /** |
||
265 | * @param EventDispatcherInterface $dispatcher |
||
266 | * @required |
||
267 | */ |
||
268 | 12 | public function setDispatcher(EventDispatcherInterface $dispatcher) |
|
276 | |||
277 | /** |
||
278 | * @param $function_name |
||
279 | * @param $arguments |
||
280 | * @param $e |
||
281 | */ |
||
282 | 2 | protected function handleFault($function_name, $arguments, $e): void |
|
293 | |||
294 | /** |
||
295 | * @param Event $event |
||
296 | * @param string $eventName |
||
297 | */ |
||
298 | 6 | private function dispatch(Event $event, $eventName) |
|
313 | } |
||
314 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: