| 1 | <?php |
||
| 20 | class DirectiveNode extends Rule |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @param Document $document |
||
| 24 | * @return TypeInvocation|DirectiveInvocation |
||
| 25 | */ |
||
| 26 | public function getTypeInvocation(Document $document): TypeInvocation |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @return string |
||
| 36 | */ |
||
| 37 | public function getDirectiveName(): string |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return iterable|DirectiveArgumentNode[] |
||
| 44 | */ |
||
| 45 | public function getDirectiveArguments(): iterable |
||
| 55 | } |
||
| 56 |
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: