| 1 | <?php |
||
| 16 | class Service extends AbstractService implements IdentityService |
||
| 17 | 1 | { |
|
| 18 | public static function factory(ClientInterface $client) |
||
| 22 | |||
| 23 | 1 | public function authenticate(array $options = []) |
|
| 40 | |||
| 41 | /** |
||
| 42 | 1 | * Generates a new authentication token |
|
| 43 | * |
||
| 44 | 1 | * @param array $options {@see \OpenStack\Identity\v2\Api::postToken} |
|
| 45 | 1 | * |
|
| 46 | * @return Models\Token |
||
| 47 | */ |
||
| 48 | public function generateToken(array $options = []) |
||
| 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: