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