Conditions | 2 |
Paths | 2 |
Total Lines | 22 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
31 | 3 | public function handle(string $bvn) |
|
32 | { |
||
33 | 3 | if (mb_strlen($bvn) !== self::VALID_BVN_LENGTH) { |
|
34 | 1 | throw new Exception( |
|
35 | 1 | "Invalid BVN.. A valid BVN should contain only 11 digits" |
|
36 | ); |
||
37 | |||
38 | } |
||
39 | |||
40 | 2 | $link = $this->baseUrl. str_replace(":bvn", $bvn, self::GET_BVN_ENDPOINT); |
|
41 | |||
42 | 2 | $response = $this->adapter->getHttpClient() |
|
|
|||
43 | 2 | ->get($link); |
|
44 | |||
45 | 2 | $this->verifyResponse($response); |
|
46 | |||
47 | //return both the data and meta keys from the array |
||
48 | 1 | return array_slice( |
|
49 | 1 | json_decode($response->getBody(), true), |
|
50 | 1 | 2 |
|
51 | ); |
||
52 | } |
||
53 | } |
||
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: