| Conditions | 1 |
| Paths | 1 |
| Total Lines | 15 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | public function testTaskPriority() |
||
| 17 | { |
||
| 18 | $task1 = new TestTask('1'); |
||
| 19 | $task2 = new TestTask('2'); |
||
| 20 | $task3 = new TestTask('3'); |
||
| 21 | |||
| 22 | $this->manager->addTask($task1); |
||
| 23 | $this->manager->addTask($task2, 5); |
||
| 24 | $this->manager->addTask($task3, 1); |
||
| 25 | |||
| 26 | $tasks = $this->manager->getTasks(); |
||
| 27 | $this->assertEquals(3, count($tasks)); |
||
| 28 | $this->assertEquals('2', $tasks[0]->getKey(), 'Task priority order is incorrect.'); |
||
|
|
|||
| 29 | $this->assertEquals('3', $tasks[1]->getKey(), 'Task priority order is incorrect.'); |
||
| 30 | } |
||
| 31 | } |
||
| 32 |
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 implementation 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 interface: