Conditions | 13 |
Paths | 9 |
Total Lines | 88 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
87 | protected function createInfo(Schema $schema, DocumentNode $document): ExtendInfo |
||
88 | { |
||
89 | $typeDefinitionMap = []; |
||
90 | $typeExtensionsMap = []; |
||
91 | $directiveDefinitions = []; |
||
92 | |||
93 | foreach ($document->getDefinitions() as $definition) { |
||
94 | if ($definition instanceof TypeDefinitionNodeInterface) { |
||
95 | // Sanity check that none of the defined types conflict with the schema's existing types. |
||
96 | $typeName = $definition->getNameValue(); |
||
97 | $existingType = $schema->getType($typeName); |
||
98 | |||
99 | if (null !== $existingType) { |
||
100 | throw new ExtensionException( |
||
101 | \sprintf( |
||
102 | 'Type "%s" already exists in the schema. It cannot also ' . |
||
103 | 'be defined in this type definition.', |
||
104 | $typeName |
||
105 | ), |
||
106 | [$definition] |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | $typeDefinitionMap[$typeName] = $definition; |
||
111 | |||
112 | continue; |
||
113 | } |
||
114 | |||
115 | if ($definition instanceof ObjectTypeExtensionNode || $definition instanceof InterfaceTypeExtensionNode) { |
||
116 | // Sanity check that this type extension exists within the schema's existing types. |
||
117 | $extendedTypeName = $definition->getNameValue(); |
||
118 | $existingType = $schema->getType($extendedTypeName); |
||
119 | |||
120 | if (null === $existingType) { |
||
121 | throw new ExtensionException( |
||
122 | \sprintf( |
||
123 | 'Cannot extend type "%s" because it does not exist in the existing schema.', |
||
124 | $extendedTypeName |
||
125 | ), |
||
126 | [$definition] |
||
127 | ); |
||
128 | } |
||
129 | |||
130 | $this->checkExtensionNode($existingType, $definition); |
||
131 | |||
132 | $typeExtensionsMap[$extendedTypeName] = \array_merge( |
||
133 | $typeExtensionsMap[$extendedTypeName] ?? [], |
||
134 | [$definition] |
||
135 | ); |
||
136 | |||
137 | continue; |
||
138 | } |
||
139 | |||
140 | if ($definition instanceof DirectiveDefinitionNode) { |
||
141 | $directiveName = $definition->getNameValue(); |
||
142 | $existingDirective = $schema->getDirective($directiveName); |
||
143 | |||
144 | if (null !== $existingDirective) { |
||
145 | throw new ExtensionException( |
||
146 | \sprintf( |
||
147 | 'Directive "%s" already exists in the schema. It cannot be redefined.', |
||
148 | $directiveName |
||
149 | ), |
||
150 | [$definition] |
||
151 | ); |
||
152 | } |
||
153 | |||
154 | $directiveDefinitions[] = $definition; |
||
155 | |||
156 | continue; |
||
157 | } |
||
158 | |||
159 | if ($definition instanceof ScalarTypeExtensionNode || |
||
160 | $definition instanceof UnionTypeExtensionNode || |
||
161 | $definition instanceof EnumTypeExtensionNode || |
||
162 | $definition instanceof InputObjectTypeExtensionNode) { |
||
163 | throw new ExtensionException( |
||
164 | \sprintf('The %s kind is not yet supported by extendSchema().', $definition->getKind()) |
||
165 | ); |
||
166 | } |
||
167 | } |
||
168 | |||
169 | return new ExtendInfo( |
||
170 | $schema, |
||
171 | $document, |
||
172 | $typeDefinitionMap, |
||
173 | $typeExtensionsMap, |
||
174 | $directiveDefinitions |
||
175 | ); |
||
200 |