1 | <?php |
||
15 | class Configuration implements ConfigurationInterface |
||
16 | { |
||
17 | /** |
||
18 | * Generates the configuration tree builder. |
||
19 | * |
||
20 | * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder |
||
21 | */ |
||
22 | 5 | public function getConfigTreeBuilder() |
|
31 | |||
32 | /** |
||
33 | * @param NodeDefinition $node |
||
34 | * |
||
35 | * @return \Symfony\Component\Config\Definition\Builder\NodeDefinition |
||
36 | */ |
||
37 | 5 | public function getConfigNode(NodeDefinition $node) |
|
60 | } |
||
61 |
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: