Total Lines | 251 |
Code Lines | 195 |
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 |
||
128 | public function provideForTestCollectFields() |
||
129 | { |
||
130 | $testCases = [ |
||
131 | [ |
||
132 | StarWarsSchema::build(), |
||
133 | 'query ShouldEmitFieldWithoutArguments { |
||
134 | human { |
||
135 | name |
||
136 | } |
||
137 | }', |
||
138 | null, |
||
139 | ], |
||
140 | [ |
||
141 | StarWarsSchema::build(), |
||
142 | 'query ShouldEmitFieldThatHasArguments($id: ID!) { |
||
143 | human(id: $id) { |
||
144 | name |
||
145 | } |
||
146 | }', |
||
147 | null, |
||
148 | ], |
||
149 | [ |
||
150 | StarWarsSchema::build(), |
||
151 | 'query ShouldEmitForInlineFragment($id: ID!) { |
||
152 | ...HumanById |
||
153 | } |
||
154 | fragment HumanById on Query { |
||
155 | human(id: $id) { |
||
156 | ... on Human { |
||
157 | name |
||
158 | } |
||
159 | } |
||
160 | }', |
||
161 | null, |
||
162 | ], |
||
163 | [ |
||
164 | StarWarsSchema::build(), |
||
165 | 'query ShouldEmitObjectFieldForFragmentSpread($id: ID!) { |
||
166 | human(id: $id) { |
||
167 | ...HumanName |
||
168 | } |
||
169 | } |
||
170 | fragment HumanName on Human { |
||
171 | name |
||
172 | }', |
||
173 | null, |
||
174 | ], |
||
175 | [ |
||
176 | StarWarsSchema::build(), |
||
177 | 'query ShouldEmitTypeName { |
||
178 | queryTypeName: __typename |
||
179 | __typename |
||
180 | }', |
||
181 | null, |
||
182 | ], |
||
183 | [ |
||
184 | StarWarsSchema::build(), |
||
185 | 'query ShouldEmitIfIncludeConditionTrue($id: ID!, $condition: Boolean!) { |
||
186 | droid(id: $id) @include(if: $condition) { |
||
187 | id |
||
188 | } |
||
189 | }', |
||
190 | ['condition' => true], |
||
191 | ], |
||
192 | [ |
||
193 | StarWarsSchema::build(), |
||
194 | 'query ShouldNotEmitIfIncludeConditionFalse($id: ID!, $condition: Boolean!) { |
||
195 | droid(id: $id) @include(if: $condition) { |
||
196 | id |
||
197 | } |
||
198 | }', |
||
199 | ['condition' => false], |
||
200 | ], |
||
201 | [ |
||
202 | StarWarsSchema::build(), |
||
203 | 'query ShouldNotEmitIfSkipConditionTrue($id: ID!, $condition: Boolean!) { |
||
204 | droid(id: $id) @skip(if: $condition) { |
||
205 | id |
||
206 | } |
||
207 | }', |
||
208 | ['condition' => true], |
||
209 | ], |
||
210 | [ |
||
211 | StarWarsSchema::build(), |
||
212 | 'query ShouldEmitIfSkipConditionFalse($id: ID!, $condition: Boolean!) { |
||
213 | droid(id: $id) @skip(if: $condition) { |
||
214 | id |
||
215 | } |
||
216 | }', |
||
217 | ['condition' => false], |
||
218 | ], |
||
219 | [ |
||
220 | StarWarsSchema::build(), |
||
221 | 'query ShouldNotEmitIncludeSkipTT($id: ID!, $includeCondition: Boolean!, $skipCondition: Boolean!) { |
||
222 | droid(id: $id) @include(if: $includeCondition) @skip(if: $skipCondition) { |
||
223 | id |
||
224 | } |
||
225 | }', |
||
226 | ['includeCondition' => true, 'skipCondition' => true], |
||
227 | ], |
||
228 | [ |
||
229 | StarWarsSchema::build(), |
||
230 | 'query ShouldEmitIncludeSkipTF($id: ID!, $includeCondition: Boolean!, $skipCondition: Boolean!) { |
||
231 | droid(id: $id) @include(if: $includeCondition) @skip(if: $skipCondition) { |
||
232 | id |
||
233 | } |
||
234 | }', |
||
235 | ['includeCondition' => true, 'skipCondition' => false], |
||
236 | ], |
||
237 | [ |
||
238 | StarWarsSchema::build(), |
||
239 | 'query ShouldNotEmitIncludeSkipFT($id: ID!, $includeCondition: Boolean!, $skipCondition: Boolean!) { |
||
240 | droid(id: $id) @include(if: $includeCondition) @skip(if: $skipCondition) { |
||
241 | id |
||
242 | } |
||
243 | }', |
||
244 | ['includeCondition' => false, 'skipCondition' => true], |
||
245 | ], |
||
246 | [ |
||
247 | StarWarsSchema::build(), |
||
248 | 'query ShouldNotEmitIncludeSkipFF($id: ID!, $includeCondition: Boolean!, $skipCondition: Boolean!) { |
||
249 | droid(id: $id) @include(if: $includeCondition) @skip(if: $skipCondition) { |
||
250 | id |
||
251 | } |
||
252 | }', |
||
253 | ['includeCondition' => false, 'skipCondition' => false], |
||
254 | ], |
||
255 | [ |
||
256 | StarWarsSchema::build(), |
||
257 | 'query ShouldNotEmitSkipAroundInlineFragment { |
||
258 | ... on Query @skip(if: true) { |
||
259 | hero(episode: 5) { |
||
260 | name |
||
261 | } |
||
262 | } |
||
263 | }', |
||
264 | null, |
||
265 | ], |
||
266 | [ |
||
267 | StarWarsSchema::build(), |
||
268 | 'query ShouldEmitSkipAroundInlineFragment { |
||
269 | ... on Query @skip(if: false) { |
||
270 | hero(episode: 5) { |
||
271 | name |
||
272 | } |
||
273 | } |
||
274 | }', |
||
275 | null, |
||
276 | ], |
||
277 | [ |
||
278 | StarWarsSchema::build(), |
||
279 | 'query ShouldEmitIncludeAroundInlineFragment { |
||
280 | ... on Query @include(if: true) { |
||
281 | hero(episode: 5) { |
||
282 | name |
||
283 | } |
||
284 | } |
||
285 | }', |
||
286 | null, |
||
287 | ], |
||
288 | [ |
||
289 | StarWarsSchema::build(), |
||
290 | 'query ShouldNotEmitIncludeAroundInlineFragment { |
||
291 | ... on Query @include(if: false) { |
||
292 | hero(episode: 5) { |
||
293 | name |
||
294 | } |
||
295 | } |
||
296 | }', |
||
297 | null, |
||
298 | ], |
||
299 | [ |
||
300 | StarWarsSchema::build(), |
||
301 | 'query ShouldNotEmitSkipFragmentSpread { |
||
302 | ...Hero @skip(if: true) |
||
303 | } |
||
304 | fragment Hero on Query { |
||
305 | hero(episode: 5) { |
||
306 | name |
||
307 | } |
||
308 | }', |
||
309 | null, |
||
310 | ], |
||
311 | [ |
||
312 | StarWarsSchema::build(), |
||
313 | 'query ShouldEmitSkipFragmentSpread { |
||
314 | ...Hero @skip(if: false) |
||
315 | } |
||
316 | fragment Hero on Query { |
||
317 | hero(episode: 5) { |
||
318 | name |
||
319 | } |
||
320 | }', |
||
321 | null, |
||
322 | ], |
||
323 | [ |
||
324 | StarWarsSchema::build(), |
||
325 | 'query ShouldEmitIncludeFragmentSpread { |
||
326 | ...Hero @include(if: true) |
||
327 | } |
||
328 | fragment Hero on Query { |
||
329 | hero(episode: 5) { |
||
330 | name |
||
331 | } |
||
332 | }', |
||
333 | null, |
||
334 | ], |
||
335 | [ |
||
336 | StarWarsSchema::build(), |
||
337 | 'query ShouldNotEmitIncludeFragmentSpread { |
||
338 | ...Hero @include(if: false) |
||
339 | } |
||
340 | fragment Hero on Query { |
||
341 | hero(episode: 5) { |
||
342 | name |
||
343 | } |
||
344 | }', |
||
345 | null, |
||
346 | ], |
||
347 | [ |
||
348 | StarWarsSchema::build(), |
||
349 | 'query ShouldEmitSingleInstrictionForSameResultName($id: ID!) { |
||
350 | human(id: $id) { |
||
351 | name |
||
352 | name: secretBackstory |
||
353 | } |
||
354 | }', |
||
355 | null, |
||
356 | ], |
||
357 | ]; |
||
358 | |||
359 | $data = []; |
||
360 | foreach ($testCases as [$schema, $query, $variableValues]) { |
||
361 | $documentNode = Parser::parse($query, ['noLocation' => true]); |
||
362 | $operationName = null; |
||
363 | foreach ($documentNode->definitions as $definitionNode) { |
||
364 | /** @var Node $definitionNode */ |
||
365 | if ($definitionNode->kind === NodeKind::OPERATION_DEFINITION) { |
||
366 | /** @var OperationDefinitionNode $definitionNode */ |
||
367 | self::assertNotNull($definitionNode->name); |
||
368 | $operationName = $definitionNode->name->value; |
||
369 | break; |
||
370 | } |
||
371 | } |
||
372 | |||
373 | self::assertArrayNotHasKey($operationName, $data); |
||
374 | |||
375 | $data[$operationName] = [$schema, $documentNode, $operationName, $variableValues]; |
||
376 | } |
||
377 | |||
378 | return $data; |
||
379 | } |
||
381 |