| 1 | <?php |
||
| 22 | final class HttpRequestAnnotHandler implements AnnotationHandler |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Sets the request method, uri, and whether or not the request contains a body |
||
| 26 | * |
||
| 27 | * @param HttpRequest|AbstractAnnotation $annotation The annotation to handle |
||
| 28 | * @param ServiceMethodBuilder $serviceMethodBuilder Used to construct a [@see ServiceMethod] |
||
| 29 | * @param Converter|null $converter Converter used to convert types before sending to service method |
||
| 30 | * @param int|null $index The position of the parameter or null if annotation does not reference parameter |
||
| 31 | * @return void |
||
| 32 | * @throws \LogicException |
||
| 33 | */ |
||
| 34 | 16 | public function handle( |
|
| 49 | } |
||
| 50 |
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: