| Conditions | 1 |
| Paths | 1 |
| Total Lines | 23 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 19 |
| CRAP Score | 1 |
| Changes | 0 | ||
| 1 | <?php |
||
| 37 | 5 | public function getConfigNode(NodeDefinition $node) |
|
| 38 | { |
||
| 39 | $node |
||
|
|
|||
| 40 | 5 | ->children() |
|
| 41 | 5 | ->scalarNode('default_client')->defaultValue('rsync')->end() |
|
| 42 | 5 | ->arrayNode('maps') |
|
| 43 | 5 | ->isRequired() |
|
| 44 | 5 | ->requiresAtLeastOneElement() |
|
| 45 | 5 | ->useAttributeAsKey('name') |
|
| 46 | 5 | ->prototype('array') |
|
| 47 | 5 | ->children() |
|
| 48 | 5 | ->scalarNode('src')->isRequired()->end() |
|
| 49 | 5 | ->scalarNode('dst')->isRequired()->end() |
|
| 50 | 5 | ->scalarNode('client')->defaultNull()->end() |
|
| 51 | 5 | ->end() |
|
| 52 | 5 | ->end() |
|
| 53 | 5 | ->end() |
|
| 54 | 5 | ->scalarNode('timeout')->defaultValue(15 * 60)->end() |
|
| 55 | 5 | ->end() |
|
| 56 | 5 | ->end(); |
|
| 57 | |||
| 58 | 5 | return $node; |
|
| 59 | } |
||
| 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: