| 1 | <?php |
||
| 22 | class FieldBuilder extends DefinitionBuilder |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @param Readable $file |
||
| 26 | * @param RuleInterface|FieldDefinitionNode $ast |
||
| 27 | * @return \Generator|mixed |
||
| 28 | */ |
||
| 29 | public function build(Readable $file, RuleInterface $ast) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param FieldDefinitionNode $ast |
||
| 47 | * @param TypeDefinition $field |
||
| 48 | * @return \Generator |
||
| 49 | */ |
||
| 50 | protected function loadArguments(FieldDefinitionNode $ast, TypeDefinition $field): \Generator |
||
| 58 | } |
||
| 59 |
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: