| Conditions | 4 |
| Paths | 3 |
| Total Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function getChildren() |
||
| 23 | { |
||
| 24 | if($this->isCurrentChildrenCacheValid) { |
||
| 25 | return $this->currentChildrenCache; |
||
| 26 | } |
||
| 27 | $children = call_user_func($this->getChildrenCallback, $this->current()); |
||
| 28 | if($children === null || $children === false) { |
||
| 29 | $children = new EmptyIterator(); |
||
| 30 | } |
||
| 31 | $this->currentChildrenCache = new self($children, $this->getChildrenCallback); |
||
| 32 | $this->isCurrentChildrenCacheValid = true; |
||
| 33 | return $this->currentChildrenCache; |
||
| 34 | } |
||
| 35 | |||
| 54 |
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 implementation 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 interface: