1 | <?php |
||
13 | class Executor implements ExecutorInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var JobInterface[] |
||
17 | */ |
||
18 | private $jobs; |
||
19 | |||
20 | /** |
||
21 | * @var EventManager |
||
22 | */ |
||
23 | private $eventManager; |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | private $processedJobs = []; |
||
29 | |||
30 | /** |
||
31 | * @param JobInterface[] $jobs |
||
32 | * |
||
33 | * @return ReportInterface |
||
34 | */ |
||
35 | public function execute(array $jobs) |
||
44 | |||
45 | /** |
||
46 | * @param CronReport $report |
||
47 | */ |
||
48 | protected function startProcesses(CronReport $report) |
||
56 | |||
57 | private function getEventManager() |
||
66 | |||
67 | /** |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function isRunning() |
||
95 | |||
96 | /** |
||
97 | * @return ShellJob[] |
||
98 | */ |
||
99 | public function getRunningJobs() |
||
110 | } |
||
111 |
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: