| Conditions | 1 |
| Paths | 1 |
| Total Lines | 12 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | public function testConstructor() { |
||
| 33 | |||
| 34 | $obj = new NavigationTree(); |
||
| 35 | |||
| 36 | $obj->addNode(new NavigationNode("main level")); |
||
| 37 | $obj->getLastNode()->setActive(true); |
||
|
|
|||
| 38 | $obj->getLastNode()->addNode(new NavigationNode("sub-level1")); |
||
| 39 | $obj->getLastNode()->getLastNode()->setActive(true); |
||
| 40 | |||
| 41 | $res = $obj->getBreadcrumbs(); |
||
| 42 | $this->assertCount(2, $res); |
||
| 43 | } |
||
| 44 | |||
| 46 |
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: