1 | <?php |
||
15 | class SelfResolver implements DefinitionResolver |
||
16 | { |
||
17 | /** |
||
18 | * @var ContainerInterface |
||
19 | */ |
||
20 | private $container; |
||
21 | |||
22 | public function __construct(ContainerInterface $container) |
||
26 | |||
27 | /** |
||
28 | * @param SelfResolvingDefinition $definition |
||
29 | * |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function resolve(Definition $definition, array $parameters = []) |
||
36 | |||
37 | /** |
||
38 | * @param SelfResolvingDefinition $definition |
||
39 | * |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function isResolvable(Definition $definition, array $parameters = []) |
||
46 | } |
||
47 |
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: