Conditions | 1 |
Paths | 1 |
Total Lines | 10 |
Code Lines | 4 |
Lines | 0 |
Ratio | 0 % |
Tests | 4 |
CRAP Score | 1 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
23 | 1 | public function createService(ServiceLocatorInterface $serviceLocator) |
|
24 | { |
||
25 | /** @var ControllerManager $serviceLocator */ |
||
26 | /** @var array $config */ |
||
27 | 1 | $config = $serviceLocator->getServiceLocator()->get('config'); |
|
|
|||
28 | /** @var ConfigMigrationServiceInterface $configMigrationService */ |
||
29 | 1 | $configMigrationService = $serviceLocator->getServiceLocator()->get('AcMailer\Service\ConfigMigrationService'); |
|
30 | |||
31 | 1 | return new ConfigMigrationController($configMigrationService, $config); |
|
32 | } |
||
33 | } |
||
34 |
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: