| 1 | <?php |
||
| 15 | class Service extends AbstractService implements IdentityService |
||
| 16 | { |
||
| 17 | 1 | public function authenticate(array $options = []) |
|
| 18 | { |
||
| 19 | 1 | $definition = $this->api->postToken(); |
|
| 20 | |||
| 21 | 1 | $response = $this->execute($definition, array_intersect_key($options, $definition['params'])); |
|
| 22 | |||
| 23 | 1 | $token = $this->model(Token::class, $response); |
|
| 24 | |||
| 25 | 1 | $serviceUrl = $this->model(Catalog::class, $response)->getServiceUrl( |
|
|
|
|||
| 26 | 1 | $options['catalogName'], |
|
| 27 | 1 | $options['catalogType'], |
|
| 28 | 1 | $options['region'], |
|
| 29 | 1 | $options['urlType'] |
|
| 30 | 1 | ); |
|
| 31 | |||
| 32 | 1 | return [$token, $serviceUrl]; |
|
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Generates a new authentication token |
||
| 37 | * |
||
| 38 | * @param array $options {@see \OpenStack\Identity\v2\Api::postToken} |
||
| 39 | * |
||
| 40 | * @return Models\Token |
||
| 41 | */ |
||
| 42 | 1 | public function generateToken(array $options = []) |
|
| 47 | } |
||
| 48 |
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: