| Conditions | 1 |
| Paths | 1 |
| Total Lines | 8 |
| Code Lines | 4 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | public function createService(ServiceLocatorInterface $serviceLocator) |
||
| 15 | { |
||
| 16 | $sm = $serviceLocator->getServiceLocator(); |
||
|
|
|||
| 17 | /** @var \Intervention\Image\ImageManager $manager */ |
||
| 18 | $manager = $sm->get('SvImages\ImageManager\InterventionImageManager'); |
||
| 19 | |||
| 20 | return new Fit($manager); |
||
| 21 | } |
||
| 22 | } |
||
| 23 |
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: