1 | <?php |
||
22 | class Configuration implements ConfigurationInterface |
||
23 | { |
||
24 | /** |
||
25 | * Whether to use the debug mode. |
||
26 | * |
||
27 | * @see https://github.com/doctrine/DoctrineBundle/blob/v1.5.2/DependencyInjection/Configuration.php#L31-L41 |
||
28 | * |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $debug; |
||
32 | |||
33 | /** |
||
34 | * @param bool $debug |
||
35 | */ |
||
36 | 26 | public function __construct($debug) |
|
40 | |||
41 | /** |
||
42 | * Generates the configuration tree builder. |
||
43 | * |
||
44 | * @return TreeBuilder The tree builder |
||
45 | */ |
||
46 | 26 | public function getConfigTreeBuilder() |
|
47 | { |
||
48 | 26 | $treeBuilder = new TreeBuilder(); |
|
49 | 26 | $rootNode = $treeBuilder->root('bazinga_geocoder'); |
|
50 | |||
51 | $rootNode |
||
52 | 26 | ->children() |
|
53 | 26 | ->append($this->getProvidersNode()) |
|
54 | 26 | ->arrayNode('profiling') |
|
55 | 26 | ->addDefaultsIfNotSet() |
|
56 | 26 | ->treatFalseLike(['enabled' => false]) |
|
57 | 26 | ->treatTrueLike(['enabled' => true]) |
|
58 | 26 | ->treatNullLike(['enabled' => $this->debug]) |
|
59 | 26 | ->info('Extend the debug profiler with information about requests.') |
|
60 | 26 | ->children() |
|
61 | 26 | ->booleanNode('enabled') |
|
62 | 26 | ->info('Turn the toolbar on or off. Defaults to kernel debug mode.') |
|
63 | 26 | ->defaultValue($this->debug) |
|
64 | 26 | ->end() |
|
65 | 26 | ->end() |
|
66 | 26 | ->end() |
|
67 | 26 | ->arrayNode('fake_ip') |
|
68 | 26 | ->beforeNormalization() |
|
69 | 26 | ->ifString() |
|
70 | 26 | ->then(function ($value) { |
|
71 | return ['ip' => $value]; |
||
72 | 26 | }) |
|
73 | 26 | ->end() |
|
74 | 26 | ->canBeEnabled() |
|
75 | 26 | ->children() |
|
76 | 26 | ->scalarNode('ip')->defaultNull()->end() |
|
77 | 26 | ->end() |
|
78 | 26 | ->end(); |
|
79 | |||
80 | 26 | return $treeBuilder; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return ArrayNodeDefinition |
||
85 | */ |
||
86 | 26 | private function getProvidersNode() |
|
112 | |||
113 | /** |
||
114 | * Create plugin node of a client. |
||
115 | * |
||
116 | * @return ArrayNodeDefinition The plugin node |
||
117 | */ |
||
118 | 26 | private function createClientPluginNode() |
|
164 | } |
||
165 |
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: