| Conditions | 14 |
| Paths | 82 |
| Total Lines | 82 |
| Code Lines | 55 |
| 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 |
||
| 38 | public function build(DocumentNode $document, array $resolverMap = [], array $options = []): SchemaInterface |
||
| 39 | { |
||
| 40 | $schemaDefinition = null; |
||
| 41 | $typeDefinitions = []; |
||
| 42 | $nodeMap = []; |
||
| 43 | $directiveDefinitions = []; |
||
| 44 | |||
| 45 | $this->definitionBuilder->setResolverMap($resolverMap); |
||
| 46 | |||
| 47 | foreach ($document->getDefinitions() as $definition) { |
||
| 48 | if ($definition instanceof SchemaDefinitionNode) { |
||
| 49 | if ($schemaDefinition) { |
||
| 50 | throw new LanguageException('Must provide only one schema definition.'); |
||
| 51 | } |
||
| 52 | $schemaDefinition = $definition; |
||
| 53 | continue; |
||
| 54 | } |
||
| 55 | |||
| 56 | if ($definition instanceof TypeDefinitionNodeInterface) { |
||
| 57 | $typeName = $definition->getNameValue(); |
||
| 58 | if (isset($nodeMap[$typeName])) { |
||
| 59 | throw new LanguageException(sprintf('Type "%s" was defined more than once.', $typeName)); |
||
| 60 | } |
||
| 61 | $typeDefinitions[] = $definition; |
||
| 62 | $nodeMap[$typeName] = $definition; |
||
| 63 | continue; |
||
| 64 | } |
||
| 65 | |||
| 66 | if ($definition instanceof DirectiveDefinitionNode) { |
||
| 67 | $directiveDefinitions[] = $definition; |
||
| 68 | continue; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | $operationTypes = null !== $schemaDefinition ? getOperationTypes($schemaDefinition, $nodeMap) : [ |
||
| 73 | 'query' => $nodeMap['Query'] ?? null, |
||
| 74 | 'mutation' => $nodeMap['Mutation'] ?? null, |
||
| 75 | 'subscription' => $nodeMap['Subscription'] ?? null, |
||
| 76 | ]; |
||
| 77 | |||
| 78 | $this->definitionBuilder->setTypeDefinitionMap($nodeMap); |
||
| 79 | |||
| 80 | $types = array_map(function (TypeDefinitionNodeInterface $definition) { |
||
| 81 | return $this->definitionBuilder->buildType($definition); |
||
| 82 | }, $typeDefinitions); |
||
| 83 | |||
| 84 | $directives = array_map(function (DirectiveDefinitionNode $definition) { |
||
| 85 | return $this->definitionBuilder->buildDirective($definition); |
||
| 86 | }, $directiveDefinitions); |
||
| 87 | |||
| 88 | if (!arraySome($directives, function (DirectiveInterface $directive) { |
||
| 89 | return $directive->getName() === 'skip'; |
||
| 90 | })) { |
||
| 91 | $directives[] = GraphQLSkipDirective(); |
||
| 92 | } |
||
| 93 | |||
| 94 | if (!arraySome($directives, function (DirectiveInterface $directive) { |
||
| 95 | return $directive->getName() === 'include'; |
||
| 96 | })) { |
||
| 97 | $directives[] = GraphQLIncludeDirective(); |
||
| 98 | } |
||
| 99 | |||
| 100 | if (!arraySome($directives, function (DirectiveInterface $directive) { |
||
| 101 | return $directive->getName() === 'deprecated'; |
||
| 102 | })) { |
||
| 103 | $directives[] = GraphQLDeprecatedDirective(); |
||
| 104 | } |
||
| 105 | |||
| 106 | return GraphQLSchema([ |
||
| 107 | 'query' => isset($operationTypes['query']) |
||
| 108 | ? $this->definitionBuilder->buildType($operationTypes['query']) |
||
| 109 | : null, |
||
| 110 | 'mutation' => isset($operationTypes['mutation']) |
||
| 111 | ? $this->definitionBuilder->buildType($operationTypes['mutation']) |
||
| 112 | : null, |
||
| 113 | 'subscription' => isset($operationTypes['subscription']) |
||
| 114 | ? $this->definitionBuilder->buildType($operationTypes['subscription']) |
||
| 115 | : null, |
||
| 116 | 'types' => $types, |
||
| 117 | 'directives' => $directives, |
||
| 118 | 'astNode' => $schemaDefinition, |
||
| 119 | 'assumeValid' => $options['assumeValid'] ?? false, |
||
| 120 | ]); |
||
| 153 |