1 | <?php |
||
19 | class RecyclingMissionManager |
||
20 | { |
||
21 | /** @var EntityManager **/ |
||
22 | protected $entityManager; |
||
23 | /** @var RealTimeActionScheduler **/ |
||
24 | protected $realtimeActionScheduler; |
||
25 | |||
26 | /** |
||
27 | * @param EntityManager $entityManager |
||
28 | * @param RealTimeActionScheduler $realtimeActionScheduler |
||
29 | */ |
||
30 | public function __construct(EntityManager $entityManager, RealTimeActionScheduler $realtimeActionScheduler) |
||
35 | |||
36 | public function scheduleMissions() |
||
49 | |||
50 | /** |
||
51 | * @param int $id |
||
52 | * @return RecyclingMission |
||
53 | */ |
||
54 | public function get($id) |
||
58 | |||
59 | /** |
||
60 | * @param int $baseId |
||
61 | * @return array |
||
62 | */ |
||
63 | public function getBaseMissions($baseId) |
||
67 | |||
68 | /** |
||
69 | * @param int $baseId |
||
70 | * @return array |
||
71 | */ |
||
72 | public function getBaseActiveMissions($baseId) |
||
76 | |||
77 | /** |
||
78 | * @param RecyclingMission $recyclingMission |
||
79 | */ |
||
80 | public function add(RecyclingMission $recyclingMission) |
||
92 | |||
93 | /** |
||
94 | * @param int $baseId |
||
95 | */ |
||
96 | public function removeBaseMissions($baseId) |
||
103 | } |
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: