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