| Conditions | 7 |
| Paths | 7 |
| Total Lines | 28 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 27 | public function find(AbstractNode $node) |
||
| 28 | { |
||
| 29 | |||
| 30 | if (!$node->id()) { |
||
| 31 | return $this->find($node->firstChild()); |
||
|
|
|||
| 32 | } |
||
| 33 | |||
| 34 | if ($node->id() == $this->id) { |
||
| 35 | return $node; |
||
| 36 | } |
||
| 37 | |||
| 38 | if ($node->hasNextSibling()) { |
||
| 39 | $nextSibling = $node->nextSibling(); |
||
| 40 | if ($nextSibling->id() == $this->id) { |
||
| 41 | return $nextSibling; |
||
| 42 | } |
||
| 43 | if ($nextSibling->id() > $this->id) { |
||
| 44 | return $this->find($node->firstChild()); |
||
| 45 | } |
||
| 46 | if ($nextSibling->id() < $this->id) { |
||
| 47 | return $this->find($nextSibling); |
||
| 48 | } |
||
| 49 | } else { |
||
| 50 | return $this->find($node->firstChild()); |
||
| 51 | } |
||
| 52 | |||
| 53 | return false; |
||
| 54 | } |
||
| 55 | |||
| 56 | } |
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: