Conditions | 1 |
Paths | 1 |
Total Lines | 13 |
Code Lines | 5 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
26 | public function createService(ServiceLocatorInterface $controllerManager) |
||
27 | { |
||
28 | /* @var ControllerManager $controllerManager*/ |
||
29 | $serviceManager = $controllerManager->getServiceLocator(); |
||
|
|||
30 | |||
31 | /* @var RedirectCallback $redirectCallback */ |
||
32 | $redirectCallback = $serviceManager->get('zfcuser_redirect_callback'); |
||
33 | |||
34 | /* @var UserController $controller */ |
||
35 | $controller = new UserController($redirectCallback); |
||
36 | |||
37 | return $controller; |
||
38 | } |
||
39 | } |
||
40 |
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: