| 1 | <?php |
||
| 22 | class FormElement extends BaseFormElement implements |
||
| 23 | TranslatorAwareInterface |
||
| 24 | { |
||
| 25 | use TranslatorAwareTrait; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * View helper service name |
||
| 29 | */ |
||
| 30 | const SERVICE = 'webinodrawformelement'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritdoc} |
||
| 34 | */ |
||
| 35 | protected function renderHelper($name, ElementInterface $element) |
||
| 47 | } |
||
| 48 |
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: