| 1 | <?php |
||
| 10 | class FriendlyInitializer implements ContextInitializer |
||
| 11 | { |
||
| 12 | protected $config; |
||
| 13 | protected $container; |
||
| 14 | |||
| 15 | public function __construct($config, ContainerInterface $container) |
||
| 20 | |||
| 21 | public function supports($context) |
||
| 25 | |||
| 26 | public function initializeContext(ContextInterface $context) |
||
| 35 | } |
||
| 36 |
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: