| Conditions | 2 |
| Paths | 2 |
| Total Lines | 15 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 2 | Features | 0 |
| 1 | <?php |
||
| 19 | public function createService(ServiceLocatorInterface $serviceLocator) |
||
| 20 | { |
||
| 21 | $request = $serviceLocator->getServiceLocator()->get('Request'); |
||
|
|
|||
| 22 | $helper = new QueryUrl($request); |
||
| 23 | |||
| 24 | $router = $serviceLocator->getServiceLocator()->get('Router'); |
||
| 25 | $match = $serviceLocator->getServiceLocator()->get('Application')->getMvcEvent()->getRouteMatch(); |
||
| 26 | |||
| 27 | if ($match instanceof RouteMatch) { |
||
| 28 | $helper->setRouteMatch($match); |
||
| 29 | } |
||
| 30 | $helper->setRouter($router); |
||
| 31 | |||
| 32 | return $helper; |
||
| 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: