1 | <?php |
||
18 | class RecyclingLogManager { |
||
19 | /** @var EntityManager **/ |
||
20 | protected $entityManager; |
||
21 | |||
22 | /** |
||
23 | * @param EntityManager $entityManager |
||
24 | */ |
||
25 | public function __construct(EntityManager $entityManager) { |
||
28 | |||
29 | /** |
||
30 | * @param RecyclingLog $recyclingLog |
||
31 | */ |
||
32 | public function add(RecyclingLog $recyclingLog) |
||
37 | |||
38 | /** |
||
39 | * @param int $baseId |
||
40 | * @return array |
||
41 | */ |
||
42 | public function getBaseActiveMissionsLogs($baseId) |
||
46 | } |
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: