Conditions | 2 |
Paths | 2 |
Total Lines | 15 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
15 | public function putProfile(): PromiseInterface |
||
16 | { |
||
17 | $fields = []; |
||
18 | foreach ($this->changedFields as $field) { |
||
19 | $fields[$field] = $this->$field; |
||
20 | } |
||
21 | |||
22 | $uri = 'account/update_profile.json?' . http_build_query($fields); |
||
23 | |||
24 | return $this->handleCommand(new RequestCommand( |
||
25 | new Request('POST', $uri) |
||
26 | ))->then(function (ResponseInterface $response) { |
||
27 | return resolve($this->handleCommand(new HydrateCommand('Profile', $response->getBody()->getJson()))); |
||
|
|||
28 | }); |
||
29 | } |
||
30 | |||
36 |
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: