Conditions | 1 |
Paths | 1 |
Total Lines | 9 |
Code Lines | 4 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
11 | public function createService(ServiceLocatorInterface $controllerManager) |
||
12 | { |
||
13 | $serviceLocator = $controllerManager->getServiceLocator(); |
||
|
|||
14 | |||
15 | /** @var Config $class */ |
||
16 | $class = $serviceLocator->get(Config::class); |
||
17 | |||
18 | return new InitController($serviceLocator->get($class->getAdapter())); |
||
19 | } |
||
20 | } |
||
21 |
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: