Completed
Pull Request — master (#36)
by Sebastian
04:13
created

Processor::introduceIntrospectionFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 8
rs 9.4285
ccs 6
cts 6
cp 1
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
/*
3
* This file is a part of graphql-youshido project.
4
*
5
* @author Portey Vasil <[email protected]>
6
* @author Alexandr Viniychuk <[email protected]>
7
* created: 11/28/15 1:05 AM
8
*/
9
10
namespace Youshido\GraphQL\Execution;
11
12
use Youshido\GraphQL\Execution\Context\ExecutionContext;
13
use Youshido\GraphQL\Execution\Visitor\AbstractQueryVisitor;
14
use Youshido\GraphQL\Field\AbstractField;
15
use Youshido\GraphQL\Field\Field;
16
use Youshido\GraphQL\Introspection\Field\SchemaField;
17
use Youshido\GraphQL\Introspection\Field\TypeDefinitionField;
18
use Youshido\GraphQL\Parser\Ast\Field as FieldAst;
19
use Youshido\GraphQL\Parser\Ast\Fragment;
20
use Youshido\GraphQL\Parser\Ast\FragmentInterface;
21
use Youshido\GraphQL\Parser\Ast\FragmentReference;
22
use Youshido\GraphQL\Parser\Ast\Mutation;
23
use Youshido\GraphQL\Parser\Ast\Query;
24
use Youshido\GraphQL\Parser\Ast\TypedFragmentReference;
25
use Youshido\GraphQL\Parser\Parser;
26
use Youshido\GraphQL\Schema\AbstractSchema;
27
use Youshido\GraphQL\Type\AbstractType;
28
use Youshido\GraphQL\Type\Object\AbstractObjectType;
29
use Youshido\GraphQL\Type\Scalar\AbstractScalarType;
30
use Youshido\GraphQL\Type\TypeInterface;
31
use Youshido\GraphQL\Type\TypeMap;
32
use Youshido\GraphQL\Type\TypeService;
33
use Youshido\GraphQL\Type\Union\AbstractUnionType;
34
use Youshido\GraphQL\Validator\Exception\ResolveException;
35
use Youshido\GraphQL\Validator\ResolveValidator\ResolveValidator;
36
use Youshido\GraphQL\Validator\ResolveValidator\ResolveValidatorInterface;
37
use Youshido\GraphQL\Validator\SchemaValidator\SchemaValidator;
38
39
class Processor
40
{
41
42
    const TYPE_NAME_QUERY = '__typename';
43
44
    /** @var  array */
45
    protected $data;
46
47
    /** @var ResolveValidatorInterface */
48
    protected $resolveValidator;
49
50
    /** @var ExecutionContext */
51
    protected $executionContext;
52
53
    /** @var int */
54
    protected $maxComplexity;
55
56 25
    public function __construct(AbstractSchema $schema)
57
    {
58 25
        $this->executionContext = new ExecutionContext();
59
        $this->executionContext->setSchema($schema);
60 24
61 24
        $this->resolveValidator = new ResolveValidator($this->executionContext);
62 24
    }
63
64 24
65 24
    public function processPayload($payload, $variables = [], $reducers = [])
66
    {
67
        if ($this->executionContext->hasErrors()) {
68 24
            $this->executionContext->clearErrors();
69
        }
70 24
71 5
        $this->data = [];
72 5
73
        try {
74 24
            $this->parseAndCreateRequest($payload, $variables);
75
76
            $queryType    = $this->executionContext->getSchema()->getQueryType();
77 24
            $mutationType = $this->executionContext->getSchema()->getMutationType();
78
79 24
            if ($this->maxComplexity) {
80 24
                $reducers[] = new \Youshido\GraphQL\Execution\Visitor\MaxComplexityQueryVisitor($this->maxComplexity);
81
            }
82 24
83 1
            $this->reduceQuery($queryType, $mutationType, $reducers);
84 1
85
            foreach ($this->executionContext->getRequest()->getOperationsInOrder() as $operation) {
86 24
                if ($operationResult = $this->executeOperation($operation, $operation instanceof Mutation ? $mutationType : $queryType)) {
87
                    $this->data = array_merge($this->data, $operationResult);
88 24
                };
89 24
            }
90 22
91 22
        } catch (\Exception $e) {
92 24
            $this->executionContext->addError($e);
93
        }
94 24
95 4
        return $this;
96
    }
97
98 24
    protected function parseAndCreateRequest($payload, $variables = [])
99
    {
100
        if (empty($payload)) {
101 24
            throw new \Exception('Must provide an operation.');
102
        }
103 24
        $parser = new Parser();
104 1
105
        $data = $parser->parse($payload);
106 24
        $this->executionContext->setRequest(new Request($data, $variables));
107
    }
108 24
109 24
    /**
110 24
     * @param Query|Field        $query
111
     * @param AbstractObjectType $currentLevelSchema
112
     * @return array|bool|mixed
113
     */
114
    protected function executeOperation(Query $query, $currentLevelSchema)
115
    {
116
        if (!$this->resolveValidator->objectHasField($currentLevelSchema, $query)) {
117 24
            return null;
118
        }
119 24
120 1
        /** @var AbstractField $field */
121
        $operationField = $currentLevelSchema->getField($query->getName());
122
        $alias          = $query->getAlias() ?: $query->getName();
123
124 24
        if (!$this->resolveValidator->validateArguments($operationField, $query, $this->executionContext->getRequest())) {
125 24
            return null;
126
        }
127 24
128 3
        return [$alias => $this->processQueryAST($query, $operationField)];
129
    }
130
131 22
    /**
132
     * @param Query         $query
133
     * @param AbstractField $field
134
     * @param               $contextValue
135
     * @return array|mixed|null
136
     */
137
    protected function processQueryAST(Query $query, AbstractField $field, $contextValue = null)
138
    {
139
        if (!$this->resolveValidator->validateArguments($field, $query, $this->executionContext->getRequest())) {
140 22
            return null;
141
        }
142 22
143
        $resolvedValue = $this->resolveFieldValue($field, $contextValue, $query);
144
145
        if (!$this->resolveValidator->isValidValueForField($field, $resolvedValue)) {
146 22
            return null;
147
        }
148 22
149 2
        return $this->collectValueForQueryWithType($query, $field->getType(), $resolvedValue);
150
    }
151
152 22
    /**
153
     * @param Query|Mutation $query
154
     * @param AbstractType   $fieldType
155
     * @param mixed          $resolvedValue
156
     * @return array|mixed
157
     */
158
    protected function collectValueForQueryWithType(Query $query, AbstractType $fieldType, $resolvedValue)
159
    {
160
        if (is_null($resolvedValue)) {
161 22
            return null;
162
        }
163 22
164 7
        $fieldType = $this->resolveValidator->resolveTypeIfAbstract($fieldType, $resolvedValue);
165
        $value = [];
166
167 20
        if ($fieldType->getKind() == TypeMap::KIND_LIST) {
168 20
            if (!$this->resolveValidator->hasArrayAccess($resolvedValue)) return null;
169
            foreach ($resolvedValue as $resolvedValueItem) {
0 ignored issues
show
Bug introduced by
The expression $resolvedValue of type object|integer|double|string|array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
170 20
                $value[] = [];
171 9
                $index   = count($value) - 1;
172 9
173 8
174 8
                $namedType = $fieldType->getNamedType();
175
                $namedType = $this->resolveValidator->resolveTypeIfAbstract($namedType, $resolvedValueItem);
176
                if (!$namedType->isValidValue($resolvedValueItem)) {
177 8
                    $this->executionContext->addError(new ResolveException(sprintf('Not valid resolve value in %s field', $query->getName())));
178 8
                    $value[$index] = null;
179 8
                    continue;
180 1
                }
181 1
182 1
                $value[$index] = $this->processQueryFields($query, $namedType, $resolvedValueItem, $value[$index]);
183
            }
184
        } else {
185 7
            if (!$query->hasFields()) {
186 9
                return $this->getOutputValue($fieldType, $resolvedValue);
187 9
            }
188 20
189 2
            $value = $this->processQueryFields($query, $fieldType, $resolvedValue, $value);
190
        }
191
192 20
        return $value;
193
    }
194
195 20
    /**
196
     * @param FieldAst      $fieldAst
197
     * @param AbstractField $field
198
     *
199
     * @param mixed         $contextValue
200
     * @return array|mixed|null
201
     * @throws ResolveException
202
     * @throws \Exception
203
     */
204
    protected function processFieldAST(FieldAst $fieldAst, AbstractField $field, $contextValue)
205
    {
206
        $value            = null;
0 ignored issues
show
Unused Code introduced by
$value is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
207 19
        $fieldType        = $field->getType();
208
        $preResolvedValue = $this->getPreResolvedValue($contextValue, $fieldAst, $field);
209 19
210 19
        if ($fieldType->getKind() == TypeMap::KIND_LIST) {
211 19
            $listValue = [];
212
            foreach ($preResolvedValue as $resolvedValueItem) {
213 19
                $type = $fieldType->getNamedType();
214 1
215 1
                if (!$type->isValidValue($resolvedValueItem)) {
216 1
                    $this->executionContext->addError(new ResolveException(sprintf('Not valid resolve value in %s field', $field->getName())));
217
218 1
                    $listValue = null;
219
                    break;
220
                }
221
                $listValue[] = $this->getOutputValue($type, $resolvedValueItem);
222
            }
223
224 1
            $value = $listValue;
225 1
        } else {
226
            $value = $this->getFieldValidatedValue($field, $preResolvedValue);
227 1
        }
228 1
229 19
        return $value;
230
    }
231
232 19
    /**
233
     * @param AbstractField $field
234
     * @param mixed         $contextValue
235
     * @param Query         $query
236
     *
237
     * @return mixed
238
     */
239
    protected function resolveFieldValue(AbstractField $field, $contextValue, Query $query)
240
    {
241
        $resolveInfo = new ResolveInfo($field, $query->getFields(), $field->getType(), $this->executionContext);
242 22
243
        if ($resolveFunc = $field->getConfig()->getResolveFunction()) {
244 22
            return $resolveFunc($contextValue, $this->parseArgumentsValues($field, $query), $resolveInfo);
245
        } elseif ($propertyValue = TypeService::getPropertyValue($contextValue, $field->getName())) {
246 22
            return $propertyValue;
247 20
        } else {
248 9
            return $field->resolve($contextValue, $this->parseArgumentsValues($field, $query), $resolveInfo);
249 1
        }
250
    }
251 8
252
    /**
253
     * @param               $contextValue
254
     * @param FieldAst      $fieldAst
255
     * @param AbstractField $field
256
     *
257
     * @throws \Exception
258
     *
259
     * @return mixed
260
     */
261
    protected function getPreResolvedValue($contextValue, FieldAst $fieldAst, AbstractField $field)
262
    {
263
        $resolved      = false;
264 19
        $resolverValue = null;
265
266 19
        if ($resolveFunction = $field->getConfig()->getResolveFunction()) {
267 19
            $resolveInfo = new ResolveInfo($field, [$fieldAst], $field->getType(), $this->executionContext);
268
269 19
            if (!$this->resolveValidator->validateArguments($field, $fieldAst, $this->executionContext->getRequest())) {
270 3
                throw new \Exception(sprintf('Not valid arguments for the field "%s"', $fieldAst->getName()));
271
272 3
            } else {
273
                $resolverValue = $resolveFunction($resolved ? $resolverValue : $contextValue, $fieldAst->getKeyValueArguments(), $resolveInfo);
274
                $resolved      = true;
275
            }
276 3
277 3
        }
278
279
        if (is_array($contextValue) && array_key_exists($fieldAst->getName(), $contextValue)) {
280 3
            $resolverValue = $contextValue[$fieldAst->getName()];
281
            $resolved      = true;
282 19
        } elseif (is_object($contextValue)) {
283 15
            $resolverValue = TypeService::getPropertyValue($contextValue, $fieldAst->getName());
284 15
            $resolved      = true;
285 19
        }
286 6
287 6
        if (!$resolved && $field->getType()->getNamedType()->getKind() == TypeMap::KIND_SCALAR) {
288 6
            $resolved = true;
289
        }
290 19
291 2
        if (!$resolverValue && !$resolved) {
292 2
            throw new \Exception(sprintf('Property "%s" not found in resolve result', $fieldAst->getName()));
293
        }
294 19
295 1
        return $resolverValue;
296
    }
297
298 19
    /**
299
     * @param $field     AbstractField
300
     * @param $query     Query
301
     *
302
     * @return array
303
     */
304
    protected function parseArgumentsValues(AbstractField $field, Query $query)
305
    {
306
        $args = [];
307 22
        foreach ($query->getArguments() as $argument) {
308
            if ($configArgument = $field->getConfig()->getArgument($argument->getName())) {
309 22
                $args[$argument->getName()] = $configArgument->getType()->parseValue($argument->getValue()->getValue());
310 22
            }
311 9
        }
312 9
313 9
        return $args;
314 22
    }
315
316 22
    /**
317
     * @param $query         Query|FragmentInterface
318
     * @param $queryType     AbstractObjectType|TypeInterface|Field|AbstractType
319
     * @param $resolvedValue mixed
320
     * @param $value         array
321
     *
322
     * @throws \Exception
323
     *
324
     * @return array
325
     */
326
    protected function processQueryFields($query, AbstractType $queryType, $resolvedValue, $value)
327
    {
328
        if ($queryType instanceof AbstractScalarType && !$query->hasFields()) {
329 20
            return $this->getOutputValue($queryType, $resolvedValue);
330
        }
331 20
332 1
        foreach ($query->getFields() as $fieldAst) {
333
            $fieldResolvedValue = null;
334
335 20
            if ($fieldAst instanceof FragmentInterface) {
336 20
                /** @var TypedFragmentReference $fragment */
337
                $fragment = $fieldAst;
338 20
                if ($fieldAst instanceof FragmentReference) {
339
                    /** @var Fragment $fragment */
340 3
                    $fragment = $this->executionContext->getRequest()->getFragment($fieldAst->getName());
341 3
                    $this->resolveValidator->assertValidFragmentForField($fragment, $fieldAst, $queryType);
342
                } elseif ($fragment->getTypeName() !== $queryType->getName()) {
343 2
                    continue;
344 2
                }
345 3
346 1
                $fragmentValue      = $this->processQueryFields($fragment, $queryType, $resolvedValue, $value);
347
                $fieldResolvedValue = is_array($fragmentValue) ? $fragmentValue : [];
348
            } else {
349 3
                $alias       = $fieldAst->getAlias() ?: $fieldAst->getName();
350 3
                $currentType = $queryType->getNullableType();
351 3
352 20
                if ($fieldAst->getName() == self::TYPE_NAME_QUERY) {
353 20
                    $fieldResolvedValue = [$alias => $queryType->getName()];
354
                } else {
355 20
                    if (!$this->resolveValidator->objectHasField($currentType, $fieldAst)) {
356 1
                        $fieldResolvedValue = null;
357 1
                    } else {
358 20
                        if ($fieldAst instanceof Query) {
359 3
                            $queryAst           = $currentType->getField($fieldAst->getName());
360 3
                            $fieldValue         = $queryAst ? $this->processQueryAST($fieldAst, $queryAst, $resolvedValue) : null;
361 20
                            $fieldResolvedValue = [$alias => $fieldValue];
362 10
                        } elseif ($fieldAst instanceof FieldAst) {
363 10
                            $fieldResolvedValue = [
364 10
                                $alias => $this->processFieldAST($fieldAst, $currentType->getField($fieldAst->getName()), $resolvedValue)
365 20
                            ];
366
                        }
367 19
                    }
368 19
369 19
370
                }
371
            }
372
373
            $value = $this->collectValue($value, $fieldResolvedValue);
374
        }
375
376 20
        return $value;
377 20
    }
378
379 20
    protected function getFieldValidatedValue(AbstractField $field, $value)
380
    {
381
        return ($this->resolveValidator->isValidValueForField($field, $value)) ? $this->getOutputValue($field->getType(), $value) : null;
382 19
    }
383
384 19
    protected function getOutputValue(AbstractType $type, $value)
385
    {
386
        return in_array($type->getKind(), [TypeMap::KIND_OBJECT, TypeMap::KIND_NON_NULL]) ? $value : $type->serialize($value);
387 19
    }
388
389 19
    protected function collectValue($value, $queryValue)
390
    {
391
        if ($queryValue && is_array($queryValue)) {
392 20
            $value = array_merge(is_array($value) ? $value : [], $queryValue);
393
        } else {
394 20
            $value = $queryValue;
395 20
        }
396 20
397 3
        return $value;
398
    }
399
400 20
    public function getResponseData()
401
    {
402
        $result = [];
403 24
404
        if (!empty($this->data)) {
405 24
            $result['data'] = $this->data;
406 24
        }
407
408 24
        if ($this->executionContext->hasErrors()) {
409 24
            $result['errors'] = $this->executionContext->getErrorsArray();
410 24
        }
411
412 24
        return $result;
413
    }
414 24
415
    public function setMaxComplexity($max)
416 24
    {
417 22
        $this->maxComplexity = $max;
418 22
    }
419
420 24
    /**
421 7
     * @param AbstractType $queryType
422 7
     * @param AbstractType $mutationType
423
     * @param array        $reducers
424 24
     */
425
    protected function reduceQuery($queryType, $mutationType, array $reducers)
426
    {
427 1
        foreach ($reducers as $reducer) {
428
            foreach ($this->executionContext->getRequest()->getOperationsInOrder() as $operation) {
429 1
                $this->doVisit($operation, $operation instanceof Mutation ? $mutationType : $queryType, $reducer);
430 1
            }
431
        }
432
    }
433
434
    /**
435
     * @param Query                $query
436
     * @param AbstractType         $currentLevelSchema
437 24
     * @param AbstractQueryVisitor $reducer
438
     */
439 24
    protected function doVisit(Query $query, $currentLevelSchema, $reducer)
440 2
    {
441 2
        if (!($currentLevelSchema instanceof AbstractObjectType) || !$currentLevelSchema->hasField($query->getName())) {
442 2
            return;
443 24
        }
444 24
445
        if ($operationField = $currentLevelSchema->getField($query->getName())) {
446
447
            $coroutine = $this->walkQuery($query, $operationField);
448
449
            if ($results = $coroutine->current()) {
450
                $queryCost = 0;
451 2
                while ($results) {
452
                    // initial values come from advancing the generator via ->current, subsequent values come from ->send()
453 2
                    list($queryField, $astField, $childCost) = $results;
454
455
                    /**
456
                     * @var Query|FieldAst $queryField
457 2
                     * @var Field          $astField
458
                     */
459 2
                    $cost = $reducer->visit($queryField->getKeyValueArguments(), $astField->getConfig(), $childCost);
460
                    $queryCost += $cost;
461 2
                    $results = $coroutine->send($cost);
462 2
                }
463 2
            }
464
        }
465 2
    }
466
467
    /**
468
     * Coroutine to walk the query and schema in DFS manner and yield a tuple of (queryNode, schemaNode, childScore)
469
     *
470
     * childScore costs are accumulated via values sent into the coroutine.
471 2
     *
472 2
     * @param Query|Field|FragmentInterface $queryNode
473 2
     * @param AbstractField                 $currentLevelAST
474 2
     *
475 2
     * @return \Generator
476 2
     */
477 2
    protected function walkQuery($queryNode, AbstractField $currentLevelAST)
478
    {
479
        $childrenScore = 0;
480
        if (!($queryNode instanceof FieldAst)) {
481
            foreach ($queryNode->getFields() as $queryField) {
0 ignored issues
show
Bug introduced by
The method getFields does only exist in Youshido\GraphQL\Field\F...raphQL\Parser\Ast\Query, but not in Youshido\GraphQL\Parser\Ast\FragmentInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
482
                if ($queryField instanceof FragmentInterface) {
483
                    if ($queryField instanceof FragmentReference) {
484
                        $queryField = $this->executionContext->getRequest()->getFragment($queryField->getName());
485
                    }
486
                    // the next 7 lines are essentially equivalent to `yield from $this->walkQuery(...)` in PHP7.
487
                    // for backwards compatibility this is equivalent.
488
                    // This pattern is repeated multiple times in this function, and unfortunately cannot be extracted or
489 2
                    // made less verbose.
490
                    $gen  = $this->walkQuery($queryField, $currentLevelAST);
0 ignored issues
show
Bug introduced by
It seems like $queryField defined by $this->executionContext-...$queryField->getName()) on line 484 can also be of type null or object<Youshido\GraphQL\Parser\Ast\Fragment>; however, Youshido\GraphQL\Execution\Processor::walkQuery() does only seem to accept object<Youshido\GraphQL\...\Ast\FragmentInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
491 2
                    $next = $gen->current();
492 2
                    while ($next) {
493 2
                        $received = (yield $next);
494 2
                        $childrenScore += (int)$received;
495 1
                        $next = $gen->send($received);
496
                    }
497
                } else {
498
                    $fieldType = $currentLevelAST->getType()->getNamedType();
499
                    if ($fieldType instanceof AbstractUnionType) {
500
                        foreach ($fieldType->getTypes() as $unionFieldType) {
501 View Code Duplication
                            if ($fieldAst = $unionFieldType->getField($queryField->getName())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
502 1
                                $gen  = $this->walkQuery($queryField, $fieldAst);
503 1
                                $next = $gen->current();
504 1
                                while ($next) {
505 1
                                    $received = (yield $next);
506 1
                                    $childrenScore += (int)$received;
507 1
                                    $next = $gen->send($received);
508 1
                                }
509 1
                            }
510 2
                        }
511 2 View Code Duplication
                    } elseif ($fieldType instanceof AbstractObjectType && $fieldAst = $fieldType->getField($queryField->getName())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
512 1
                        $gen  = $this->walkQuery($queryField, $fieldAst);
513 1
                        $next = $gen->current();
514 1
                        while ($next) {
515 1
                            $received = (yield $next);
516 1
                            $childrenScore += (int)$received;
517 1
                            $next = $gen->send($received);
518 1
                        }
519 1
                    }
520 1
                }
521 1
            }
522 1
        }
523 2
        // sanity check.  don't yield fragments; they don't contribute to cost
524 1
        if ($queryNode instanceof Query || $queryNode instanceof FieldAst) {
525 1
            yield [$queryNode, $currentLevelAST, $childrenScore];
526 1
        }
527 1
    }
528
}
529