| Conditions | 1 |
| Paths | 1 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | public function getConfigTreeBuilder() |
||
| 30 | { |
||
| 31 | $treeBuilder = new TreeBuilder('magento'); |
||
| 32 | |||
| 33 | $treeBuilder->getRootNode() |
||
|
|
|||
| 34 | ->children() |
||
| 35 | ->arrayNode('connections')->info('List all available connections') |
||
| 36 | ->requiresAtLeastOneElement() |
||
| 37 | ->useAttributeAsKey('default') |
||
| 38 | ->prototype('array') |
||
| 39 | ->children() |
||
| 40 | ->scalarNode('url')->isRequired()->cannotBeEmpty()->example('http://domain.tld/magento/')->end() |
||
| 41 | ->scalarNode('api_user')->isRequired()->cannotBeEmpty()->example('username')->end() |
||
| 42 | ->scalarNode('api_key')->isRequired()->cannotBeEmpty()->example('0123456789AZ')->end() |
||
| 43 | ->booleanNode('logging')->defaultValue(false)->info('Enable logging system')->example('%kernel.debug%')->end() |
||
| 44 | ->scalarNode('logger')->defaultValue(null)->info('Refers to the logger service')->end() |
||
| 45 | ->scalarNode('dispatcher')->defaultValue(null)->info('Refers to the dispatcher service')->end() |
||
| 46 | ->end() |
||
| 47 | ->end() |
||
| 48 | ->end() |
||
| 49 | ->scalarNode('default_connection')->defaultValue('default')->info('Refers to the default connection in the connection pool')->example('default') |
||
| 50 | ->end() |
||
| 51 | ->end() |
||
| 52 | ; |
||
| 53 | |||
| 54 | return $treeBuilder; |
||
| 55 | } |
||
| 56 | } |
||
| 57 |
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: