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