| 1 | <?php |
||
| 23 | class NoneSource implements Component |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @return string |
||
| 27 | */ |
||
| 28 | public function name(): string |
||
| 32 | |||
| 33 | /** |
||
| 34 | * {@inheritdoc} |
||
| 35 | */ |
||
| 36 | public function load(array $configs, ContainerBuilder $container) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | public function getNodeDefinition(NodeDefinition $node) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * {@inheritdoc} |
||
| 60 | */ |
||
| 61 | public function prepend(ContainerBuilder $container, array $config): array |
||
| 65 | } |
||
| 66 |
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 sub-classes 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 parent class: