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