1 | <?php |
||
7 | final class LoadingReferenceProvider implements ReferenceProviderInterface |
||
8 | { |
||
9 | /** |
||
10 | * @var ManagerRegistry |
||
11 | */ |
||
12 | private $registry; |
||
13 | |||
14 | /** |
||
15 | * PartialReferenceProvider constructor. |
||
16 | * |
||
17 | * @param ManagerRegistry $registry |
||
18 | */ |
||
19 | public function __construct(ManagerRegistry $registry) |
||
23 | |||
24 | /** {@inheritdoc} */ |
||
25 | public function getEntityReference($fqcn, $property, $identifier) |
||
37 | } |
||
38 |
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: