Conditions | 1 |
Paths | 1 |
Total Lines | 17 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 1 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
23 | 1 | public function authenticate(array $options = []) |
|
24 | { |
||
25 | 1 | $definition = $this->api->postToken(); |
|
26 | 1 | ||
27 | 1 | $response = $this->execute($definition, array_intersect_key($options, $definition['params'])); |
|
28 | 1 | ||
29 | 1 | $token = $this->model(Token::class, $response); |
|
30 | 1 | ||
31 | $serviceUrl = $this->model(Catalog::class, $response)->getServiceUrl( |
||
|
|||
32 | 1 | $options['catalogName'], |
|
33 | $options['catalogType'], |
||
34 | $options['region'], |
||
35 | $options['urlType'] |
||
36 | ); |
||
37 | |||
38 | return [$token, $serviceUrl]; |
||
39 | } |
||
40 | |||
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: