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