| 1 | <?php |
||
| 18 | abstract class AbstractSource |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @param ContainerBuilder $container |
||
| 22 | * @param array $config |
||
| 23 | * |
||
| 24 | * @return Definition |
||
| 25 | */ |
||
| 26 | abstract protected function createDefinition(ContainerBuilder $container, array $config): Definition; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | public function create(ContainerBuilder $container, string $type, string $name, array $config) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param NodeDefinition $node |
||
| 41 | */ |
||
| 42 | public function addConfiguration(NodeDefinition $node) |
||
| 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 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: