Conditions | 2 |
Paths | 2 |
Total Lines | 18 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
29 | 3 | public function handle(array $params) |
|
30 | { |
||
31 | 3 | if (!$this->isValid($params)) { |
|
32 | 1 | throw new Exception( |
|
33 | 1 | "Invalid params.. The params should contain an 'account_number' key and 'bank_code' key" |
|
34 | ); |
||
35 | |||
36 | } |
||
37 | |||
38 | 2 | $link = $this->baseUrl. self::GET_ACCOUNT_DETAILS_ENDPOINT . toQueryParams($params); |
|
39 | |||
40 | 2 | $response = $this->adapter->getHttpClient() |
|
|
|||
41 | 2 | ->get($link); |
|
42 | |||
43 | 2 | $this->verifyResponse($response); |
|
44 | |||
45 | 1 | return json_decode($response->getBody(), true)["data"]; |
|
46 | } |
||
47 | |||
54 |
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: