1 | <?php |
||
24 | class SchemaBuilder extends Builder |
||
25 | { |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private const FIELD_QUERY = 'query'; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private const FIELD_MUTATION = 'mutation'; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | private const FIELD_SUBSCRIPTION = 'subscription'; |
||
40 | |||
41 | /** |
||
42 | * @param RuleInterface|SchemaDefinitionNode $rule |
||
43 | * @param Definition $parent |
||
44 | * @return Definition |
||
45 | * @throws \Railt\Io\Exception\ExternalFileException |
||
46 | */ |
||
47 | public function build(RuleInterface $rule, Definition $parent): Definition |
||
63 | |||
64 | /** |
||
65 | * @param SchemaDefinitionNode $rule |
||
66 | * @param SchemaDefinition $schema |
||
67 | * @throws \Railt\Io\Exception\ExternalFileException |
||
68 | */ |
||
69 | private function buildSchemaFields(SchemaDefinitionNode $rule, SchemaDefinition $schema): void |
||
103 | |||
104 | /** |
||
105 | * @param string $field |
||
106 | * @param TypeHintNode $hint |
||
107 | * @param SchemaDefinition $schema |
||
108 | * @throws \Railt\Io\Exception\ExternalFileException |
||
109 | */ |
||
110 | private function validateModifiers(string $field, TypeHintNode $hint, SchemaDefinition $schema): void |
||
118 | |||
119 | /** |
||
120 | * @param string $field |
||
121 | * @param SchemaFieldDefinitionNode $rule |
||
122 | * @param SchemaDefinition $schema |
||
123 | * @throws \Railt\Io\Exception\ExternalFileException |
||
124 | */ |
||
125 | private function validateFieldName(string $field, SchemaFieldDefinitionNode $rule, SchemaDefinition $schema): void |
||
133 | } |
||
134 |
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: