Conditions | 13 |
Paths | 26 |
Total Lines | 69 |
Code Lines | 36 |
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 |
||
71 | protected function createContext( |
||
72 | Schema $schema, |
||
73 | DocumentNode $documentNode, |
||
74 | $rootValue, |
||
75 | $contextValue, |
||
76 | $rawVariableValues, |
||
77 | $operationName = null, |
||
78 | callable $fieldResolver = null |
||
79 | ): ExecutionContext { |
||
80 | $errors = []; |
||
81 | $fragments = []; |
||
82 | $operation = null; |
||
83 | |||
84 | foreach ($documentNode->getDefinitions() as $definition) { |
||
85 | if ($definition instanceof OperationDefinitionNode) { |
||
86 | if (!$operationName && $operation) { |
||
87 | throw new ExecutionException( |
||
88 | 'Must provide operation name if query contains multiple operations.' |
||
89 | ); |
||
90 | } |
||
91 | |||
92 | if (!$operationName || $definition->getNameValue() === $operationName) { |
||
93 | $operation = $definition; |
||
94 | } |
||
95 | |||
96 | continue; |
||
97 | } |
||
98 | |||
99 | if ($definition instanceof FragmentDefinitionNode || $definition instanceof FragmentSpreadNode) { |
||
100 | $fragments[$definition->getNameValue()] = $definition; |
||
101 | |||
102 | continue; |
||
103 | } |
||
104 | } |
||
105 | |||
106 | if (null === $operation) { |
||
107 | if (null !== $operationName) { |
||
108 | throw new ExecutionException(sprintf('Unknown operation named "%s".', $operationName)); |
||
109 | } |
||
110 | |||
111 | throw new ExecutionException('Must provide an operation.'); |
||
112 | } |
||
113 | |||
114 | $variableValues = []; |
||
115 | |||
116 | /** @var OperationDefinitionNode $operation */ |
||
117 | if (null !== $operation) { |
||
118 | $coercedVariableValues = coerceVariableValues( |
||
119 | $schema, |
||
120 | $operation->getVariableDefinitions(), |
||
121 | $rawVariableValues |
||
122 | ); |
||
123 | |||
124 | $variableValues = $coercedVariableValues->getValue(); |
||
125 | |||
126 | if ($coercedVariableValues->hasErrors()) { |
||
127 | $errors = $coercedVariableValues->getErrors(); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | return new ExecutionContext( |
||
132 | $schema, |
||
133 | $fragments, |
||
134 | $rootValue, |
||
135 | $contextValue, |
||
136 | $variableValues, |
||
137 | $fieldResolver, |
||
138 | $operation, |
||
139 | $errors |
||
140 | ); |
||
152 |