| 1 | <?php |
||
| 14 | class MassUpdater |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var RegistryInterface |
||
| 18 | */ |
||
| 19 | protected $doctrine; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Constructor |
||
| 23 | * |
||
| 24 | * @param RegistryInterface $doctrine |
||
| 25 | */ |
||
| 26 | public function __construct(RegistryInterface $doctrine) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Mass updates entities |
||
| 33 | * |
||
| 34 | * @param string $class |
||
| 35 | * @param array $data |
||
| 36 | * @param array $ids |
||
| 37 | */ |
||
| 38 | public function updateEntities($class, array $data, array $ids) |
||
| 50 | } |
||
| 51 |
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: