1 | <?php |
||
25 | class SchemaBuilder extends Builder |
||
26 | { |
||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private const FIELD_QUERY = 'query'; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private const FIELD_MUTATION = 'mutation'; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private const FIELD_SUBSCRIPTION = 'subscription'; |
||
41 | |||
42 | /** |
||
43 | * @param RuleInterface|SchemaDefinitionNode $rule |
||
44 | * @param Definition $parent |
||
45 | * @return Definition |
||
46 | * @throws \Railt\Io\Exception\ExternalFileException |
||
47 | */ |
||
48 | public function build(RuleInterface $rule, Definition $parent): Definition |
||
62 | |||
63 | /** |
||
64 | * @param SchemaDefinitionNode $rule |
||
65 | * @param SchemaDefinition $schema |
||
66 | * @throws \Railt\Io\Exception\ExternalFileException |
||
67 | */ |
||
68 | private function buildSchemaFields(SchemaDefinitionNode $rule, SchemaDefinition $schema): void |
||
92 | |||
93 | /** |
||
94 | * @param string $field |
||
95 | * @param TypeHintNode $hint |
||
96 | * @param SchemaDefinition $schema |
||
97 | * @throws \Railt\Io\Exception\ExternalFileException |
||
98 | */ |
||
99 | private function validateModifiers(string $field, TypeHintNode $hint, SchemaDefinition $schema): void |
||
109 | |||
110 | /** |
||
111 | * @param string $field |
||
112 | * @param SchemaFieldDefinitionNode $rule |
||
113 | * @param SchemaDefinition $schema |
||
114 | * @throws \Railt\Io\Exception\ExternalFileException |
||
115 | */ |
||
116 | private function validateFieldName(string $field, SchemaFieldDefinitionNode $rule, SchemaDefinition $schema): void |
||
124 | } |
||
125 |
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: