| Conditions | 2 |
| Paths | 2 |
| Total Lines | 13 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 44 | 2 | protected function makeBodyParams( |
|
| 45 | string $customerIdentifier, |
||
| 46 | string $planCode, |
||
| 47 | string $customerAuth |
||
| 48 | ): array { |
||
| 49 | 2 | $bodyParams = ["customer" => $customerIdentifier, "plan" => $planCode]; |
|
| 50 | |||
| 51 | 2 | if ($customerAuth) { |
|
| 52 | 1 | $bodyParams["authorization"] = $customerAuth; |
|
| 53 | } |
||
| 54 | |||
| 55 | 2 | return $bodyParams; |
|
| 56 | } |
||
| 57 | } |
||
| 58 |
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: