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