| Conditions | 3 |
| Paths | 3 |
| Total Lines | 10 |
| Code Lines | 7 |
| Lines | 10 |
| Ratio | 100 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 66 | View Code Duplication | public static function toString($visibility) |
|
| 67 | { |
||
| 68 | if ($visibility === Class_::MODIFIER_PUBLIC) { |
||
| 69 | return 'public'; |
||
| 70 | } elseif ($visibility === Class_::MODIFIER_PROTECTED) { |
||
| 71 | return 'protected'; |
||
| 72 | } else { |
||
| 73 | return 'private'; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 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: