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