Conditions | 1 |
Paths | 1 |
Total Lines | 38 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
26 | public function getConfigTreeBuilder() |
||
27 | { |
||
28 | $autodiscoverNode = new ArrayNodeDefinition('autodiscover'); |
||
29 | $autodiscoverNode |
||
|
|||
30 | ->info('Autodiscover classes stored in the configured directory of bundles and register them as service.') |
||
31 | ->canBeDisabled() |
||
32 | ->children() |
||
33 | ->arrayNode('directories') |
||
34 | ->info('The directories name to autodiscover in bundles.') |
||
35 | ->prototype('scalar')->end() |
||
36 | ->defaultValue(['Action']) |
||
37 | ->end() |
||
38 | ->end(); |
||
39 | |||
40 | $directoriesNode = new ArrayNodeDefinition('directories'); |
||
41 | $directoriesNode |
||
42 | ->info('List of directories relative to the kernel root directory containing action classes.') |
||
43 | ->prototype('scalar')->end() |
||
44 | ->defaultValue([]); |
||
45 | |||
46 | $treeBuilder = new TreeBuilder(); |
||
47 | $treeBuilder->root('dunglas_action') |
||
48 | ->children() |
||
49 | ->arrayNode('actions') |
||
50 | ->canBeDisabled() |
||
51 | ->append($autodiscoverNode) |
||
52 | ->append($directoriesNode) |
||
53 | ->end() |
||
54 | ->arrayNode('commands') |
||
55 | ->canBeDisabled() |
||
56 | ->append($autodiscoverNode) |
||
57 | ->append($directoriesNode) |
||
58 | ->end() |
||
59 | ->end() |
||
60 | ->end(); |
||
61 | |||
62 | return $treeBuilder; |
||
63 | } |
||
64 | } |
||
65 |
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: