Conditions | 16 |
Paths | 11 |
Total Lines | 101 |
Code Lines | 60 |
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 |
||
93 | protected function createInfo(Schema $schema, DocumentNode $document): ExtendInfo |
||
94 | { |
||
95 | $typeDefinitionMap = []; |
||
96 | $typeExtensionsMap = []; |
||
97 | $directiveDefinitions = []; |
||
98 | $schemaExtensions = []; |
||
99 | |||
100 | foreach ($document->getDefinitions() as $definition) { |
||
101 | if ($definition instanceof SchemaDefinitionNode) { |
||
102 | // Sanity check that a schema extension is not defining a new schema |
||
103 | throw new SchemaExtensionException('Cannot define a new schema within a schema extension.', [$definition]); |
||
104 | } |
||
105 | |||
106 | if ($definition instanceof SchemaExtensionNode) { |
||
107 | $schemaExtensions[] = $definition; |
||
108 | |||
109 | continue; |
||
110 | } |
||
111 | |||
112 | if ($definition instanceof DirectiveDefinitionNode) { |
||
113 | $directiveName = $definition->getNameValue(); |
||
114 | $existingDirective = $schema->getDirective($directiveName); |
||
|
|||
115 | |||
116 | if (null !== $existingDirective) { |
||
117 | throw new SchemaExtensionException( |
||
118 | \sprintf( |
||
119 | 'Directive "%s" already exists in the schema. It cannot be redefined.', |
||
120 | $directiveName |
||
121 | ), |
||
122 | [$definition] |
||
123 | ); |
||
124 | } |
||
125 | |||
126 | $directiveDefinitions[] = $definition; |
||
127 | |||
128 | continue; |
||
129 | } |
||
130 | |||
131 | if ($definition instanceof TypeSystemDefinitionNodeInterface && $definition instanceof NameAwareInterface) { |
||
132 | // Sanity check that none of the defined types conflict with the schema's existing types. |
||
133 | $typeName = $definition->getNameValue(); |
||
134 | $existingType = $schema->getType($typeName); |
||
135 | |||
136 | if (null !== $existingType) { |
||
137 | throw new SchemaExtensionException( |
||
138 | \sprintf( |
||
139 | 'Type "%s" already exists in the schema. It cannot also ' . |
||
140 | 'be defined in this type definition.', |
||
141 | $typeName |
||
142 | ), |
||
143 | [$definition] |
||
144 | ); |
||
145 | } |
||
146 | |||
147 | $typeDefinitionMap[$typeName] = $definition; |
||
148 | |||
149 | continue; |
||
150 | } |
||
151 | |||
152 | if ($definition instanceof ObjectTypeExtensionNode || $definition instanceof InterfaceTypeExtensionNode) { |
||
153 | // Sanity check that this type extension exists within the schema's existing types. |
||
154 | $extendedTypeName = $definition->getNameValue(); |
||
155 | $existingType = $schema->getType($extendedTypeName); |
||
156 | |||
157 | if (null === $existingType) { |
||
158 | throw new SchemaExtensionException( |
||
159 | \sprintf( |
||
160 | 'Cannot extend type "%s" because it does not exist in the existing schema.', |
||
161 | $extendedTypeName |
||
162 | ), |
||
163 | [$definition] |
||
164 | ); |
||
165 | } |
||
166 | |||
167 | $this->checkExtensionNode($existingType, $definition); |
||
168 | |||
169 | $typeExtensionsMap[$extendedTypeName] = \array_merge( |
||
170 | $typeExtensionsMap[$extendedTypeName] ?? [], |
||
171 | [$definition] |
||
172 | ); |
||
173 | |||
174 | continue; |
||
175 | } |
||
176 | |||
177 | if ($definition instanceof ScalarTypeExtensionNode || |
||
178 | $definition instanceof UnionTypeExtensionNode || |
||
179 | $definition instanceof EnumTypeExtensionNode || |
||
180 | $definition instanceof InputObjectTypeExtensionNode) { |
||
181 | throw new SchemaExtensionException( |
||
182 | \sprintf('The %s kind is not yet supported by extendSchema().', $definition->getKind()) |
||
183 | ); |
||
184 | } |
||
185 | } |
||
186 | |||
187 | return new ExtendInfo( |
||
188 | $schema, |
||
189 | $document, |
||
190 | $typeDefinitionMap, |
||
191 | $typeExtensionsMap, |
||
192 | $directiveDefinitions, |
||
193 | $schemaExtensions |
||
194 | ); |
||
219 |