Conditions | 3 |
Paths | 2 |
Total Lines | 32 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
27 | public function call(string $method, array $arguments = []) |
||
28 | { |
||
29 | $xml = [ |
||
30 | 'methodCall' => [ |
||
31 | 'methodName' => $method, |
||
32 | ], |
||
33 | ]; |
||
34 | |||
35 | if (count($arguments) > 0) { |
||
36 | $xml['params'] = $arguments; |
||
37 | } |
||
38 | |||
39 | return $this->requestService->request(new Request( |
||
40 | 'POST', |
||
41 | '', |
||
42 | [], |
||
43 | new XmlStream($xml) |
||
44 | ))->then(function (ResponseInterface $response) { |
||
45 | $xml = $response->getBody()->getParsedContents(); |
||
|
|||
46 | |||
47 | if (isset($xml['methodResponse']['fault'])) { |
||
48 | return reject( |
||
49 | new XmlRpcError( |
||
50 | $xml['methodResponse']['fault']['value']['struct']['member'][1]['value']['string'], |
||
51 | (int)$xml['methodResponse']['fault']['value']['struct']['member'][0]['value']['int'] |
||
52 | ) |
||
53 | ); |
||
54 | } |
||
55 | |||
56 | return resolve($xml['methodResponse']['params']['param']); |
||
57 | }); |
||
58 | } |
||
59 | } |
||
60 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: