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