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