1 | <?php |
||
20 | final class SkipDirective extends DirectiveDefinition |
||
21 | { |
||
22 | /** |
||
23 | * @var string[] |
||
24 | */ |
||
25 | private const LOCATIONS = [ |
||
26 | DirectiveLocation::FIELD, |
||
27 | DirectiveLocation::FRAGMENT_SPREAD, |
||
28 | DirectiveLocation::INLINE_FRAGMENT, |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | public const TYPE_NAME = 'skip'; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | public const TYPE_DESCRIPTION = <<<Description |
||
40 | The @skip directive may be provided for fields, fragment spreads, and inline fragments, |
||
41 | and allows for conditional exclusion during execution as described by the if argument. |
||
42 | Description; |
||
43 | |||
44 | /** |
||
45 | * BooleanScalar constructor. |
||
46 | * @param Document $document |
||
47 | */ |
||
48 | 9 | public function __construct(Document $document) |
|
60 | |||
61 | /** |
||
62 | * @return int |
||
63 | */ |
||
64 | public function getLine(): int |
||
68 | |||
69 | /** |
||
70 | * @return bool |
||
71 | */ |
||
72 | public function isBuiltin(): bool |
||
76 | } |
||
77 |
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: