Conditions | 1 |
Paths | 1 |
Total Lines | 11 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Tests | 6 |
CRAP Score | 1 |
Changes | 0 |
1 | <?php |
||
28 | 2 | public function handle(array $data) |
|
29 | { |
||
30 | 2 | $response = $this->adapter->getHttpClient() |
|
|
|||
31 | 2 | ->post($this->baseUrl . self::CREATE_PLAN_ENDPOINT, [ |
|
32 | 2 | "body" => json_encode($data) |
|
33 | ]); |
||
34 | |||
35 | 2 | $this->verifyResponse($response); |
|
36 | |||
37 | 1 | return json_decode($response->getBody(), true)["data"]; |
|
38 | } |
||
39 | } |
||
40 |
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: