1 | <?php |
||
20 | final class DeprecatedDirective extends DirectiveDefinition |
||
21 | { |
||
22 | /** |
||
23 | * @var string[] |
||
24 | */ |
||
25 | private const LOCATIONS = [ |
||
26 | DirectiveLocation::OBJECT, |
||
27 | DirectiveLocation::INTERFACE, |
||
28 | DirectiveLocation::FIELD_DEFINITION, |
||
29 | DirectiveLocation::SCALAR, |
||
30 | DirectiveLocation::UNION, |
||
31 | DirectiveLocation::ENUM, |
||
32 | DirectiveLocation::ENUM_VALUE, |
||
33 | DirectiveLocation::INPUT_OBJECT, |
||
34 | DirectiveLocation::INPUT_UNION, |
||
35 | DirectiveLocation::INPUT_FIELD_DEFINITION, |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | public const TYPE_NAME = 'deprecated'; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | public const TYPE_DESCRIPTION = <<<Description |
||
47 | The @deprecated directive is used within the type system definition language to |
||
48 | indicate deprecated portions of a GraphQL service’s schema, such as deprecated |
||
49 | fields on a type or deprecated enum values. |
||
50 | Description; |
||
51 | |||
52 | /** |
||
53 | * BooleanScalar constructor. |
||
54 | * @param Document $document |
||
55 | */ |
||
56 | public function __construct(Document $document) |
||
68 | |||
69 | /** |
||
70 | * @return int |
||
71 | */ |
||
72 | public function getLine(): int |
||
76 | |||
77 | /** |
||
78 | * @return bool |
||
79 | */ |
||
80 | public function isBuiltin(): bool |
||
84 | } |
||
85 |
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: