1 | <?php |
||
18 | abstract class Entity extends \ORM\Entity { |
||
19 | |||
20 | /** |
||
21 | * @return array |
||
22 | * @codeCoverageIgnore |
||
23 | */ |
||
24 | public function getDataAsArray() |
||
28 | |||
29 | /** |
||
30 | * @param EntityManager $dbManager |
||
31 | * @return Entity|\ORM\Entity|bool |
||
32 | * @codeCoverageIgnore |
||
33 | */ |
||
34 | public function save(EntityManager $dbManager = null, $redirectOnDuplicateKey = false) |
||
65 | |||
66 | } |
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: