| Conditions | 3 | 
| Paths | 4 | 
| Total Lines | 12 | 
| Code Lines | 9 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php | ||
| 22 | 	protected function createItem($value) { | ||
| 23 | $icon=$value; | ||
| 24 | 		if (\is_array($value)) { | ||
| 25 | $icon=JArray::getValue($value, "icon", 0); | ||
| 26 | $size=JArray::getValue($value, "size", 1); | ||
| 27 | } | ||
| 28 | 		$iconO=new HtmlIcon("icon-" . $this->identifier, $icon); | ||
| 29 | 		if (isset($size)) { | ||
| 30 | $iconO->setSize($size); | ||
| 31 | } | ||
| 32 | return $iconO; | ||
| 33 | } | ||
| 34 | |||
| 47 | } | 
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: