| 1 | <?php |
||
| 26 | class ConfirmationFactory implements FactoryInterface, MutableCreationOptionsInterface |
||
| 27 | { |
||
| 28 | private $options = []; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Set creation options |
||
| 32 | * |
||
| 33 | * @param array $options |
||
| 34 | * |
||
| 35 | * @return void |
||
| 36 | */ |
||
| 37 | public function setCreationOptions(array $options) |
||
| 41 | |||
| 42 | |||
| 43 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
||
| 56 | |||
| 57 | public function createService(ServiceLocatorInterface $serviceLocator) |
||
| 64 | } |
||
| 65 |
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: