Conditions | 2 |
Paths | 2 |
Total Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 2.004 |
Changes | 0 |
1 | <?php |
||
16 | 2 | public function getConfigTreeBuilder() |
|
17 | { |
||
18 | 2 | $treeBuilder = new TreeBuilder('happyr_google_site_authenticator'); |
|
19 | // Keep compatibility with symfony/config < 4.2 |
||
20 | 2 | if (!method_exists($treeBuilder, 'getRootNode')) { |
|
21 | $root = $treeBuilder->root('happyr_google_site_authenticator'); |
||
22 | } else { |
||
23 | 2 | $root = $treeBuilder->getRootNode(); |
|
24 | } |
||
25 | |||
26 | 2 | $root->children() |
|
27 | 2 | ->scalarNode('cache_service')->cannotBeEmpty()->end() |
|
28 | 2 | ->append($this->getTokenNode()) |
|
29 | 2 | ->end(); |
|
30 | |||
31 | 2 | return $treeBuilder; |
|
32 | } |
||
33 | |||
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: