| Conditions | 1 |
| Paths | 1 |
| Total Lines | 8 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function createService(ServiceLocatorInterface $serviceLocator) |
||
| 23 | { |
||
| 24 | $parentLocator = $serviceLocator->getServiceLocator(); |
||
|
|
|||
| 25 | $objectManager = $parentLocator->get('JhFlexiTime\ObjectManager'); |
||
| 26 | $user = $parentLocator->get('zfcuser_auth_service')->getIdentity(); |
||
| 27 | $bookingFieldset = new BookingFieldset($objectManager, $user); |
||
| 28 | return new BookingForm($objectManager, $bookingFieldset); |
||
| 29 | } |
||
| 30 | } |
||
| 31 |
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: