Conditions | 7 |
Paths | 7 |
Total Lines | 26 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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->firstChild()); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | return false; |
||
52 | } |
||
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: