Conditions | 1 |
Paths | 1 |
Total Lines | 19 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 1 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
47 | 11 | protected function getApp() |
|
48 | { |
||
49 | 11 | return (new TreeBuilder()) |
|
|
|||
50 | 11 | ->root('app') |
|
51 | 11 | ->isRequired() |
|
52 | 11 | ->children() |
|
53 | 11 | ->integerNode('version') |
|
54 | 11 | ->isRequired() |
|
55 | 11 | ->end() |
|
56 | 11 | ->scalarNode('client') |
|
57 | 11 | ->cannotBeEmpty() |
|
58 | 11 | ->isRequired() |
|
59 | 11 | ->end() |
|
60 | 11 | ->scalarNode('code') |
|
61 | 11 | ->cannotBeEmpty() |
|
62 | 11 | ->isRequired() |
|
63 | 11 | ->end() |
|
64 | 11 | ->end(); |
|
65 | } |
||
66 | } |
||
67 |
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: