| Conditions | 3 |
| Paths | 2 |
| Total Lines | 12 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 3.0175 |
| 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 | return; |
||
| 25 | } |
||
| 26 | |||
| 27 | 2 | throw new ResponseErrorException($response->getReasonPhrase(), [ |
|
| 28 | 2 | 'request' => $response->getRequest()->getParts(), |
|
| 29 | 2 | 'response' => $response->getData(), |
|
| 30 | 2 | ], $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: