| Conditions | 1 |
| Paths | 1 |
| Total Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 1 |
| Changes | 0 | ||
| 1 | <?php |
||
| 37 | 2 | private function getTokenNode() |
|
| 38 | { |
||
| 39 | 2 | $treeBuilder = new TreeBuilder(); |
|
| 40 | 2 | $node = $treeBuilder->root('tokens'); |
|
| 41 | $node |
||
|
|
|||
| 42 | 2 | ->isRequired() |
|
| 43 | 2 | ->requiresAtLeastOneElement() |
|
| 44 | 2 | ->useAttributeAsKey('name') |
|
| 45 | 2 | ->prototype('array') |
|
| 46 | 2 | ->children() |
|
| 47 | 2 | ->scalarNode('client_id')->isRequired()->end() |
|
| 48 | 2 | ->scalarNode('client_secret')->isRequired()->end() |
|
| 49 | 2 | ->scalarNode('redirect_url')->isRequired()->end() |
|
| 50 | 2 | ->variableNode('scopes')->end() |
|
| 51 | 2 | ->end() |
|
| 52 | 2 | ->end(); |
|
| 53 | |||
| 54 | 2 | return $node; |
|
| 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: