Conditions | 3 |
Paths | 2 |
Total Lines | 12 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 4 |
CRAP Score | 4.125 |
Changes | 0 |
1 | <?php |
||
20 | 2 | public function checkResponse(ResponseInterface $response) |
|
21 | { |
||
22 | 2 | $code = $response->getStatusCode(); |
|
|
|||
23 | 2 | if ($code >= 200 && $code < 300) { |
|
24 | 2 | return; |
|
25 | } |
||
26 | |||
27 | throw new ResponseErrorException($response->getReasonPhrase(), [ |
||
28 | 'request' => $response->getRequest()->getParts(), |
||
29 | 'response' => $response->getData(), |
||
30 | ], $code); |
||
31 | } |
||
32 | } |
||
33 |
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: