1 | <?php |
||
24 | final class PartAnnotHandler implements AnnotationHandler |
||
25 | { |
||
26 | /** |
||
27 | * Handle an annotation, mutating the [@see ServiceMethodBuilder] based on the value |
||
28 | * |
||
29 | * @param Part|AbstractAnnotation $annotation The annotation to handle |
||
30 | * @param ServiceMethodBuilder $serviceMethodBuilder Used to construct a [@see ServiceMethod] |
||
31 | * @param Converter|RequestBodyConverter $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: