Conditions | 2 |
Paths | 2 |
Total Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 2.0054 |
Changes | 0 |
1 | <?php |
||
11 | 2 | public function getConfigTreeBuilder() |
|
12 | { |
||
13 | 2 | $tb = new TreeBuilder('goetas_multipart_upload'); |
|
14 | |||
15 | 2 | if (method_exists($tb, 'goetas_multipart_upload')) { |
|
16 | $root = $tb->getRootNode()->children(); |
||
|
|||
17 | } else { |
||
18 | 2 | $root = $tb->root('jms_serializer')->children(); |
|
19 | } |
||
20 | |||
21 | $root |
||
22 | 2 | ->booleanNode('first_part_as_default') |
|
23 | 2 | ->defaultTrue() |
|
24 | 2 | ->end(); |
|
25 | |||
26 | 2 | return $tb; |
|
27 | } |
||
28 | |||
30 |
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: