| Conditions | 1 |
| Paths | 1 |
| Total Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | public function process(RuleInterface $ast): ?TypeDefinition |
||
| 28 | { |
||
| 29 | /** @var DirectiveDefinition $directive */ |
||
| 30 | $directive = $ast->getTypeDefinition(); |
||
|
|
|||
| 31 | |||
| 32 | $this->immediately(function () use ($ast, $directive) { |
||
| 33 | $directive->withOffset($ast->getOffset()); |
||
| 34 | $directive->withDescription($ast->getDescription()); |
||
| 35 | }); |
||
| 36 | |||
| 37 | return $directive; |
||
| 38 | } |
||
| 39 | } |
||
| 40 |
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: