1 | <?php |
||
17 | class TechnologyQueueManager |
||
18 | { |
||
19 | /** @var EntityManager **/ |
||
20 | protected $entityManager; |
||
21 | /** @var RealTimeActionScheduler **/ |
||
22 | protected $realtimeActionScheduler; |
||
23 | |||
24 | /** |
||
25 | * @param EntityManager $entityManager |
||
26 | * @param RealTimeActionScheduler $realtimeActionScheduler |
||
27 | */ |
||
28 | public function __construct(EntityManager $entityManager, RealTimeActionScheduler $realtimeActionScheduler) |
||
33 | |||
34 | public function scheduleQueues() |
||
42 | |||
43 | /** |
||
44 | * @param int $id |
||
45 | * @return TechnologyQueue |
||
46 | */ |
||
47 | public function get($id) |
||
51 | |||
52 | /** |
||
53 | * @param int $playerId |
||
54 | * @param int $technology |
||
55 | * @return TechnologyQueue |
||
56 | */ |
||
57 | public function getPlayerTechnologyQueue($playerId, $technology) |
||
61 | |||
62 | /** |
||
63 | * @param int $placeId |
||
64 | * @return array |
||
65 | */ |
||
66 | public function getPlaceQueues($placeId) |
||
70 | |||
71 | /** |
||
72 | * @param int $playerId |
||
73 | * @return array |
||
74 | */ |
||
75 | public function getPlayerQueues($playerId) |
||
79 | |||
80 | /** |
||
81 | * @param TechnologyQueue $technologyQueue |
||
82 | */ |
||
83 | public function add(TechnologyQueue $technologyQueue) { |
||
89 | } |
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: