| Conditions | 1 |
| Paths | 1 |
| Total Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 28 | public function createService(ServiceLocatorInterface $drawHelpers) |
||
| 29 | { |
||
| 30 | $services = $drawHelpers->getServiceLocator(); |
||
|
|
|||
| 31 | $viewHelpers = $services->get('ViewHelperManager'); |
||
| 32 | $formRow = $viewHelpers->get(FormRow::SERVICE); |
||
| 33 | |||
| 34 | $formCollection = clone $viewHelpers->get('FormCollection'); |
||
| 35 | $formCollection->setDefaultElementHelper(FormRow::SERVICE); |
||
| 36 | |||
| 37 | $form = new Form( |
||
| 38 | $services, |
||
| 39 | $formRow, |
||
| 40 | $formRow->getElementHelper(), |
||
| 41 | $viewHelpers->get('FormElementErrors'), |
||
| 42 | $formCollection, |
||
| 43 | $viewHelpers->get('Url'), |
||
| 44 | $services->get(InstructionsRenderer::class) |
||
| 45 | ); |
||
| 46 | |||
| 47 | $form->setEventManager($services->get('EventManager')); |
||
| 48 | return $form; |
||
| 49 | } |
||
| 50 | } |
||
| 51 |
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: