| Conditions | 10 |
| Paths | 7 |
| Total Lines | 51 |
| Code Lines | 29 |
| 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 |
||
| 27 | public function buildContext( |
||
| 28 | Schema $schema, |
||
| 29 | DocumentNode $documentNode, |
||
| 30 | $rootValue, |
||
| 31 | $contextValue, |
||
| 32 | $rawVariableValues, |
||
| 33 | $operationName = null, |
||
| 34 | callable $fieldResolver = null |
||
| 35 | ): ExecutionContext { |
||
| 36 | //@TODO validate $rawVariableValues? |
||
| 37 | |||
| 38 | $errors = []; |
||
| 39 | $fragments = []; |
||
| 40 | $operation = null; |
||
| 41 | |||
| 42 | foreach ($documentNode->getDefinitions() as $definition) { |
||
| 43 | switch ($definition->getKind()) { |
||
| 44 | case NodeKindEnum::OPERATION_DEFINITION: |
||
| 45 | if (!$operationName && $operation) { |
||
| 46 | throw new GraphQLError( |
||
| 47 | 'Must provide operation name if query contains multiple operations.' |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | if (!$operationName || (!empty($definition->getName()) && $definition->getName()->getValue() === $operationName)) { |
||
| 52 | $operation = $definition; |
||
| 53 | } |
||
| 54 | break; |
||
| 55 | case NodeKindEnum::FRAGMENT_DEFINITION: |
||
| 56 | case NodeKindEnum::FRAGMENT_SPREAD: |
||
| 57 | $fragments[$definition->getName()->getValue()] = $definition; |
||
| 58 | break; |
||
| 59 | default: |
||
| 60 | throw new GraphQLError( |
||
| 61 | "GraphQL cannot execute a request containing a {$definition->getKind()}." |
||
| 62 | ); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | $executionContext = new ExecutionContext( |
||
| 67 | $schema, |
||
| 68 | $fragments, |
||
| 69 | $rootValue, |
||
| 70 | $contextValue, |
||
| 71 | $rawVariableValues, |
||
| 72 | $fieldResolver, |
||
| 73 | $operation, |
||
| 74 | $errors |
||
| 75 | ); |
||
| 76 | |||
| 77 | return $executionContext; |
||
| 78 | } |
||
| 79 | } |