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 | |||
45 | /** |
||
46 | * @param int $id |
||
47 | * @return TechnologyQueue |
||
48 | */ |
||
49 | public function get($id) |
||
53 | |||
54 | /** |
||
55 | * @param int $playerId |
||
56 | * @param int $technology |
||
57 | * @return TechnologyQueue |
||
58 | */ |
||
59 | public function getPlayerTechnologyQueue($playerId, $technology) |
||
63 | |||
64 | /** |
||
65 | * @param int $placeId |
||
66 | * @return array |
||
67 | */ |
||
68 | public function getPlaceQueues($placeId) |
||
72 | |||
73 | /** |
||
74 | * @param int $playerId |
||
75 | * @return array |
||
76 | */ |
||
77 | public function getPlayerQueues($playerId) |
||
81 | |||
82 | /** |
||
83 | * @param TechnologyQueue $technologyQueue |
||
84 | */ |
||
85 | public function add(TechnologyQueue $technologyQueue) { |
||
91 | |||
92 | /** |
||
93 | * @param TechnologyQueue $queue |
||
94 | */ |
||
95 | public function remove(TechnologyQueue $queue) |
||
102 | } |
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: