Conditions | 1 |
Paths | 1 |
Total Lines | 20 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | public function createService(ServiceLocatorInterface $formElementManager) |
||
20 | { |
||
21 | $fem = $formElementManager; |
||
22 | $sm = $formElementManager->getServiceLocator(); |
||
|
|||
23 | |||
24 | $options = $sm->get('zfcuser_module_options'); |
||
25 | $form = new Form\ChangeEmail(null, $options); |
||
26 | // Inject the FormElementManager to support custom FormElements |
||
27 | $form->getFormFactory()->setFormElementManager($fem); |
||
28 | |||
29 | $form->setInputFilter(new Form\ChangeEmailFilter( |
||
30 | $options, |
||
31 | new Validator\NoRecordExists(array( |
||
32 | 'mapper' => $sm->get('zfcuser_user_mapper'), |
||
33 | 'key' => 'email' |
||
34 | )) |
||
35 | )); |
||
36 | |||
37 | return $form; |
||
38 | } |
||
39 | } |
||
40 |
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: