| 1 | <?php |
||
| 24 | final class FieldMapAnnotHandler implements AnnotationHandler |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * Set the content type to form encoded and adds a parameter handler for a field map |
||
| 28 | * |
||
| 29 | * @param FieldMap|AbstractAnnotation $annotation The annotation to handle |
||
| 30 | * @param ServiceMethodBuilder $serviceMethodBuilder Used to construct a [@see ServiceMethod] |
||
| 31 | * @param Converter|StringConverter $converter Converter used to convert types before sending to service method |
||
| 32 | * @param int|null $index The position of the parameter or null if annotation does not reference parameter |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | 2 | public function handle( |
|
| 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 sub-classes 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 parent class: