Conditions | 1 |
Paths | 1 |
Total Lines | 10 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
24 | public function createService(ServiceLocatorInterface $serviceManager) |
||
25 | { |
||
26 | $serviceLocator = $serviceManager->getServiceLocator(); |
||
|
|||
27 | $authService = $serviceLocator->get('zfcuser_auth_service'); |
||
28 | $authAdapter = $serviceLocator->get('ZfcUser\Authentication\Adapter\AdapterChain'); |
||
29 | $controllerPlugin = new Controller\Plugin\ZfcUserAuthentication; |
||
30 | $controllerPlugin->setAuthService($authService); |
||
31 | $controllerPlugin->setAuthAdapter($authAdapter); |
||
32 | return $controllerPlugin; |
||
33 | } |
||
34 | } |
||
35 |
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: