| 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 |
||
| 122 | protected function createContext( |
||
| 123 | Schema $schema, |
||
| 124 | DocumentNode $documentNode, |
||
| 125 | $rootValue, |
||
| 126 | $contextValue, |
||
| 127 | $rawVariableValues, |
||
| 128 | ?string $operationName = null, |
||
| 129 | ?callable $fieldResolver = null |
||
| 130 | ): ExecutionContext { |
||
| 131 | $errors = []; |
||
| 132 | $fragments = []; |
||
| 133 | $operation = null; |
||
| 134 | |||
| 135 | foreach ($documentNode->getDefinitions() as $definition) { |
||
| 136 | if ($definition instanceof OperationDefinitionNode) { |
||
| 137 | if (null === $operationName && null !== $operation) { |
||
| 138 | throw new ExecutionException( |
||
| 139 | 'Must provide operation name if query contains multiple operations.' |
||
| 140 | ); |
||
| 141 | } |
||
| 142 | |||
| 143 | if (null === $operationName || $definition->getNameValue() === $operationName) { |
||
| 144 | $operation = $definition; |
||
| 145 | } |
||
| 146 | |||
| 147 | continue; |
||
| 148 | } |
||
| 149 | |||
| 150 | if ($definition instanceof FragmentDefinitionNode || $definition instanceof FragmentSpreadNode) { |
||
| 151 | $fragments[$definition->getNameValue()] = $definition; |
||
| 152 | |||
| 153 | continue; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | if (null === $operation) { |
||
| 158 | if (null !== $operationName) { |
||
| 159 | throw new ExecutionException(sprintf('Unknown operation named "%s".', $operationName)); |
||
| 160 | } |
||
| 161 | |||
| 162 | throw new ExecutionException('Must provide an operation.'); |
||
| 163 | } |
||
| 164 | |||
| 165 | $coercedVariableValues = (new ValuesResolver())->coerceVariableValues( |
||
| 166 | $schema, |
||
| 167 | $operation->getVariableDefinitions(), |
||
| 168 | $rawVariableValues |
||
| 169 | ); |
||
| 170 | |||
| 171 | $variableValues = $coercedVariableValues->getValue(); |
||
| 172 | |||
| 173 | if ($coercedVariableValues->hasErrors()) { |
||
| 174 | $errors = $coercedVariableValues->getErrors(); |
||
| 175 | } |
||
| 176 | |||
| 177 | return new ExecutionContext( |
||
| 178 | $schema, |
||
| 179 | $fragments, |
||
| 180 | $rootValue, |
||
| 181 | $contextValue, |
||
| 182 | $variableValues, |
||
| 183 | $fieldResolver, |
||
| 184 | $operation, |
||
| 185 | $errors |
||
| 186 | ); |
||
| 189 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.