| Conditions | 12 |
| Paths | 21 |
| Total Lines | 64 |
| Code Lines | 34 |
| 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 |
||
| 86 | protected function createContext( |
||
| 87 | Schema $schema, |
||
| 88 | DocumentNode $documentNode, |
||
| 89 | $rootValue, |
||
| 90 | $contextValue, |
||
| 91 | $rawVariableValues, |
||
| 92 | ?string $operationName = null, |
||
| 93 | ?callable $fieldResolver = null |
||
| 94 | ): ExecutionContext { |
||
| 95 | $errors = []; |
||
| 96 | $fragments = []; |
||
| 97 | $operation = null; |
||
| 98 | |||
| 99 | foreach ($documentNode->getDefinitions() as $definition) { |
||
| 100 | if ($definition instanceof OperationDefinitionNode) { |
||
| 101 | if (null === $operationName && $operation) { |
||
| 102 | throw new ExecutionException( |
||
| 103 | 'Must provide operation name if query contains multiple operations.' |
||
| 104 | ); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (null === $operationName || $definition->getNameValue() === $operationName) { |
||
| 108 | $operation = $definition; |
||
| 109 | } |
||
| 110 | |||
| 111 | continue; |
||
| 112 | } |
||
| 113 | |||
| 114 | if ($definition instanceof FragmentDefinitionNode || $definition instanceof FragmentSpreadNode) { |
||
| 115 | $fragments[$definition->getNameValue()] = $definition; |
||
| 116 | |||
| 117 | continue; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | if (null === $operation) { |
||
| 122 | if (null !== $operationName) { |
||
| 123 | throw new ExecutionException(sprintf('Unknown operation named "%s".', $operationName)); |
||
| 124 | } |
||
| 125 | |||
| 126 | throw new ExecutionException('Must provide an operation.'); |
||
| 127 | } |
||
| 128 | |||
| 129 | $coercedVariableValues = coerceVariableValues( |
||
| 130 | $schema, |
||
| 131 | $operation->getVariableDefinitions(), |
||
| 132 | $rawVariableValues |
||
| 133 | ); |
||
| 134 | |||
| 135 | $variableValues = $coercedVariableValues->getValue(); |
||
| 136 | |||
| 137 | if ($coercedVariableValues->hasErrors()) { |
||
| 138 | $errors = $coercedVariableValues->getErrors(); |
||
| 139 | } |
||
| 140 | |||
| 141 | return new ExecutionContext( |
||
| 142 | $schema, |
||
| 143 | $fragments, |
||
| 144 | $rootValue, |
||
| 145 | $contextValue, |
||
| 146 | $variableValues, |
||
| 147 | $fieldResolver, |
||
| 148 | $operation, |
||
| 149 | $errors |
||
| 150 | ); |
||
| 162 |