Conditions | 3 |
Paths | 3 |
Total Lines | 10 |
Code Lines | 7 |
Lines | 10 |
Ratio | 100 % |
Tests | 6 |
CRAP Score | 3 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
51 | 97 | View Code Duplication | public static function getModifier($visibility) |
52 | { |
||
53 | 97 | if ($visibility === 'public') { |
|
54 | 41 | return Class_::MODIFIER_PUBLIC; |
|
55 | 56 | } elseif ($visibility === 'protected') { |
|
56 | 28 | return Class_::MODIFIER_PROTECTED; |
|
57 | } else { |
||
58 | 28 | return Class_::MODIFIER_PRIVATE; |
|
59 | } |
||
60 | } |
||
61 | |||
77 |
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: