Conditions | 1 |
Paths | 1 |
Total Lines | 35 |
Lines | 35 |
Ratio | 100 % |
Changes | 0 |
1 | <?php |
||
31 | public function getConfigTreeBuilder() |
||
32 | { |
||
33 | $treeBuilder = new TreeBuilder('swp_redirect_route'); |
||
34 | $treeBuilder->getRootNode() |
||
|
|||
35 | ->children() |
||
36 | ->arrayNode('persistence') |
||
37 | ->addDefaultsIfNotSet() |
||
38 | ->children() |
||
39 | ->arrayNode('orm') |
||
40 | ->addDefaultsIfNotSet() |
||
41 | ->canBeEnabled() |
||
42 | ->children() |
||
43 | ->arrayNode('classes') |
||
44 | ->addDefaultsIfNotSet() |
||
45 | ->children() |
||
46 | ->arrayNode('redirect_route') |
||
47 | ->addDefaultsIfNotSet() |
||
48 | ->children() |
||
49 | ->scalarNode('model')->cannotBeEmpty()->defaultValue(RedirectRoute::class)->end() |
||
50 | ->scalarNode('repository')->defaultValue(EntityRepository::class)->end() |
||
51 | ->scalarNode('factory')->defaultValue(Factory::class)->end() |
||
52 | ->scalarNode('interface')->defaultValue(RedirectRouteInterface::class)->end() |
||
53 | ->scalarNode('object_manager_name')->defaultValue(null)->end() |
||
54 | ->end() |
||
55 | ->end() |
||
56 | ->end() |
||
57 | ->end() |
||
58 | ->end() |
||
59 | ->end() |
||
60 | ->end() |
||
61 | ->end() |
||
62 | ; |
||
63 | |||
64 | return $treeBuilder; |
||
65 | } |
||
66 | } |
||
67 |
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: