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