1 | <?php |
||
17 | class SchemaValidator |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * @param AbstractSchema $schema |
||
22 | * |
||
23 | * @throws ConfigurationException |
||
24 | */ |
||
25 | 5 | public function validate(AbstractSchema $schema) |
|
26 | { |
||
27 | 5 | if (!$schema->getQueryType()->hasFields()) { |
|
28 | 1 | throw new ConfigurationException('Schema has to have fields'); |
|
29 | } |
||
30 | 4 | foreach ($schema->getQueryType()->getConfig()->getFields() as $field) { |
|
|
|||
31 | 4 | if ($field->getType() instanceof AbstractObjectType) { |
|
32 | 4 | $this->assertInterfaceImplementationCorrect($field->getType()); |
|
33 | 1 | } |
|
34 | 1 | } |
|
35 | 1 | } |
|
36 | |||
37 | /** |
||
38 | * @param AbstractObjectType $type |
||
39 | * |
||
40 | * @throws ConfigurationException |
||
41 | */ |
||
42 | 4 | protected function assertInterfaceImplementationCorrect(AbstractObjectType $type) |
|
43 | { |
||
44 | 4 | if (!$type->getInterfaces()) { |
|
45 | return; |
||
46 | } |
||
47 | |||
48 | 4 | foreach ($type->getInterfaces() as $interface) { |
|
49 | 4 | foreach ($interface->getConfig()->getFields() as $intField) { |
|
50 | 4 | $this->assertFieldsIdentical($intField, $type->getConfig()->getField($intField->getName()), $interface); |
|
51 | 1 | } |
|
52 | 1 | } |
|
53 | 1 | } |
|
54 | |||
55 | /** |
||
56 | * @param Field $intField |
||
57 | * @param Field $objField |
||
58 | * @param AbstractInterfaceType $interface |
||
59 | * |
||
60 | * @return bool |
||
61 | * |
||
62 | * @throws ConfigurationException |
||
63 | */ |
||
64 | 4 | protected function assertFieldsIdentical($intField, $objField, AbstractInterfaceType $interface) |
|
78 | } |
||
79 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: