Conditions | 3 |
Paths | 2 |
Total Lines | 32 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
43 | public function callRaw(string $method, array $arguments = []) |
||
44 | { |
||
45 | $xml = [ |
||
46 | 'methodCall' => [ |
||
47 | 'methodName' => $method, |
||
48 | ], |
||
49 | ]; |
||
50 | |||
51 | if (count($arguments) > 0) { |
||
52 | $xml['methodCall']['params'] = $arguments; |
||
53 | } |
||
54 | |||
55 | return $this->requestService->request(new Request( |
||
56 | 'POST', |
||
57 | '', |
||
58 | [], |
||
59 | new XmlStream($xml) |
||
60 | ))->then(function (ResponseInterface $response) { |
||
61 | $xml = $response->getBody()->getParsedContents(); |
||
|
|||
62 | |||
63 | if (isset($xml['methodResponse']['fault'])) { |
||
64 | return reject( |
||
65 | new XmlRpcError( |
||
66 | $xml['methodResponse']['fault']['value']['struct']['member'][1]['value']['string'], |
||
67 | (int)$xml['methodResponse']['fault']['value']['struct']['member'][0]['value']['int'] |
||
68 | ) |
||
69 | ); |
||
70 | } |
||
71 | |||
72 | return resolve($xml['methodResponse']['params']['param']); |
||
73 | }); |
||
74 | } |
||
75 | } |
||
76 |
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: