| 1 | <?php |
||
| 16 | class UrlConfig extends HydratorItem implements ItemConfig |
||
| 17 | { |
||
| 18 | const OPTION_URL = 'url'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param string $className |
||
| 22 | * @param array $arguments |
||
| 23 | * @return mixed |
||
| 24 | */ |
||
| 25 | protected function getObject(string $className, array $arguments) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param Url|Item $object |
||
| 35 | * @return array |
||
| 36 | */ |
||
| 37 | protected function getArray($object): array |
||
| 45 | |||
| 46 | protected function config() |
||
| 52 | } |
||
| 53 |
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: