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