Completed
Push — master ( e891dc...f1a729 )
by Alexandr
03:27
created

Processor::getFieldValidatedValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 2
cts 2
cp 1
cc 2
eloc 2
nc 2
nop 2
crap 2
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
        (new SchemaValidator())->validate($schema);
59
60 24
        $this->introduceIntrospectionFields($schema);
61 24
        $this->executionContext = new ExecutionContext();
62 24
        $this->executionContext->setSchema($schema);
63
64 24
        $this->resolveValidator = new ResolveValidator($this->executionContext);
65 24
    }
66
67
68 24
    public function processPayload($payload, $variables = [], $reducers = [])
69
    {
70 24
        if ($this->executionContext->hasErrors()) {
71 5
            $this->executionContext->clearErrors();
72 5
        }
73
74 24
        $this->data = [];
75
76
        try {
77 24
            $this->parseAndCreateRequest($payload, $variables);
78
79 24
            $queryType    = $this->executionContext->getSchema()->getQueryType();
80 24
            $mutationType = $this->executionContext->getSchema()->getMutationType();
81
82 24
            if ($this->maxComplexity) {
83 1
                $reducers[] = new \Youshido\GraphQL\Execution\Visitor\MaxComplexityQueryVisitor($this->maxComplexity);
84 1
            }
85
86 24
            $this->reduceQuery($queryType, $mutationType, $reducers);
87
88 24
            foreach ($this->executionContext->getRequest()->getOperationsInOrder() as $operation) {
89 24
                if ($operationResult = $this->executeOperation($operation, $operation instanceof Mutation ? $mutationType : $queryType)) {
90 22
                    $this->data = array_merge($this->data, $operationResult);
91 22
                };
92 24
            }
93
94 24
        } catch (\Exception $e) {
95 4
            $this->executionContext->addError($e);
96
        }
97
98 24
        return $this;
99
    }
100
101 24
    protected function parseAndCreateRequest($payload, $variables = [])
102
    {
103 24
        if (empty($payload)) {
104 1
            throw new \Exception('Must provide an operation.');
105
        }
106 24
        $parser = new Parser();
107
108 24
        $data = $parser->parse($payload);
109 24
        $this->executionContext->setRequest(new Request($data, $variables));
110 24
    }
111
112
    /**
113
     * @param Query|Field        $query
114
     * @param AbstractObjectType $currentLevelSchema
115
     * @return array|bool|mixed
116
     */
117 24
    protected function executeOperation(Query $query, $currentLevelSchema)
118
    {
119 24
        if (!$this->resolveValidator->objectHasField($currentLevelSchema, $query)) {
120 1
            return null;
121
        }
122
123
        /** @var AbstractField $field */
124 24
        $operationField = $currentLevelSchema->getField($query->getName());
125 24
        $alias          = $query->getAlias() ?: $query->getName();
126
127 24
        if (!$this->resolveValidator->validateArguments($operationField, $query, $this->executionContext->getRequest())) {
128 3
            return null;
129
        }
130
131 22
        return [$alias => $this->processQueryAST($query, $operationField)];
132
    }
133
134
    /**
135
     * @param Query         $query
136
     * @param AbstractField $field
137
     * @param               $contextValue
138
     * @return array|mixed|null
139
     */
140 22
    protected function processQueryAST(Query $query, AbstractField $field, $contextValue = null)
141
    {
142 22
        if (!$this->resolveValidator->validateArguments($field, $query, $this->executionContext->getRequest())) {
143
            return null;
144
        }
145
146 22
        $resolvedValue = $this->resolveFieldValue($field, $contextValue, $query);
147
148 22
        if (!$this->resolveValidator->isValidValueForField($field, $resolvedValue)) {
149 2
            return null;
150
        }
151
152 22
        return $this->collectValueForQueryWithType($query, $field->getType(), $resolvedValue);
153
    }
154
155
    /**
156
     * @param Query|Mutation $query
157
     * @param AbstractType   $fieldType
158
     * @param mixed          $resolvedValue
159
     * @return array|mixed
160
     */
161 22
    protected function collectValueForQueryWithType(Query $query, AbstractType $fieldType, $resolvedValue)
162
    {
163 22
        if (is_null($resolvedValue)) {
164 7
            return null;
165
        }
166
167 20
        $fieldType = $this->resolveValidator->resolveTypeIfAbstract($fieldType, $resolvedValue);
168 20
        $value = [];
169
170 20
        if ($fieldType->getKind() == TypeMap::KIND_LIST) {
171 9
            if (!$this->resolveValidator->hasArrayAccess($resolvedValue)) return null;
172 9
            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...
173 8
                $value[] = [];
174 8
                $index   = count($value) - 1;
175
176
177 8
                $namedType = $fieldType->getNamedType();
178 8
                $namedType = $this->resolveValidator->resolveTypeIfAbstract($namedType, $resolvedValueItem);
179 8
                if (!$namedType->isValidValue($resolvedValueItem)) {
180 1
                    $this->executionContext->addError(new ResolveException(sprintf('Not valid resolve value in %s field', $query->getName())));
181 1
                    $value[$index] = null;
182 1
                    continue;
183
                }
184
185 7
                $value[$index] = $this->processQueryFields($query, $namedType, $resolvedValueItem, $value[$index]);
186 9
            }
187 9
        } else {
188 20
            if (!$query->hasFields()) {
189 2
                return $this->getOutputValue($fieldType, $resolvedValue);
190
            }
191
192 20
            $value = $this->processQueryFields($query, $fieldType, $resolvedValue, $value);
193
        }
194
195 20
        return $value;
196
    }
197
198
    /**
199
     * @param FieldAst      $fieldAst
200
     * @param AbstractField $field
201
     *
202
     * @param mixed         $contextValue
203
     * @return array|mixed|null
204
     * @throws ResolveException
205
     * @throws \Exception
206
     */
207 19
    protected function processFieldAST(FieldAst $fieldAst, AbstractField $field, $contextValue)
208
    {
209 19
        $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...
210 19
        $fieldType        = $field->getType();
211 19
        $preResolvedValue = $this->getPreResolvedValue($contextValue, $fieldAst, $field);
212
213 19
        if ($fieldType->getKind() == TypeMap::KIND_LIST) {
214 1
            $listValue = [];
215 1
            foreach ($preResolvedValue as $resolvedValueItem) {
216 1
                $type = $fieldType->getNamedType();
217
218 1
                if (!$type->isValidValue($resolvedValueItem)) {
219
                    $this->executionContext->addError(new ResolveException(sprintf('Not valid resolve value in %s field', $field->getName())));
220
221
                    $listValue = null;
222
                    break;
223
                }
224 1
                $listValue[] = $this->getOutputValue($type, $resolvedValueItem);
225 1
            }
226
227 1
            $value = $listValue;
228 1
        } else {
229 19
            $value = $this->getFieldValidatedValue($field, $preResolvedValue);
230
        }
231
232 19
        return $value;
233
    }
234
235
    /**
236
     * @param AbstractField $field
237
     * @param mixed         $contextValue
238
     * @param Query         $query
239
     *
240
     * @return mixed
241
     */
242 22
    protected function resolveFieldValue(AbstractField $field, $contextValue, Query $query)
243
    {
244 22
        $resolveInfo = new ResolveInfo($field, $query->getFields(), $field->getType(), $this->executionContext);
245
246 22
        if ($resolveFunc = $field->getConfig()->getResolveFunction()) {
247 20
            return $resolveFunc($contextValue, $this->parseArgumentsValues($field, $query), $resolveInfo);
248 9
        } elseif ($propertyValue = TypeService::getPropertyValue($contextValue, $field->getName())) {
249 1
            return $propertyValue;
250
        } else {
251 8
            return $field->resolve($contextValue, $this->parseArgumentsValues($field, $query), $resolveInfo);
252
        }
253
    }
254
255
    /**
256
     * @param               $contextValue
257
     * @param FieldAst      $fieldAst
258
     * @param AbstractField $field
259
     *
260
     * @throws \Exception
261
     *
262
     * @return mixed
263
     */
264 19
    protected function getPreResolvedValue($contextValue, FieldAst $fieldAst, AbstractField $field)
265
    {
266 19
        $resolved      = false;
267 19
        $resolverValue = null;
268
269 19
        if ($resolveFunction = $field->getConfig()->getResolveFunction()) {
270 3
            $resolveInfo = new ResolveInfo($field, [$fieldAst], $field->getType(), $this->executionContext);
271
272 3
            if (!$this->resolveValidator->validateArguments($field, $fieldAst, $this->executionContext->getRequest())) {
273
                throw new \Exception(sprintf('Not valid arguments for the field "%s"', $fieldAst->getName()));
274
275
            } else {
276 3
                $resolverValue = $resolveFunction($resolved ? $resolverValue : $contextValue, $fieldAst->getKeyValueArguments(), $resolveInfo);
277 3
                $resolved      = true;
278
            }
279
280 3
        }
281
282 19
        if (is_array($contextValue) && array_key_exists($fieldAst->getName(), $contextValue)) {
283 15
            $resolverValue = $contextValue[$fieldAst->getName()];
284 15
            $resolved      = true;
285 19
        } elseif (is_object($contextValue)) {
286 6
            $resolverValue = TypeService::getPropertyValue($contextValue, $fieldAst->getName());
287 6
            $resolved      = true;
288 6
        }
289
290 19
        if (!$resolved && $field->getType()->getNamedType()->getKind() == TypeMap::KIND_SCALAR) {
291 2
            $resolved = true;
292 2
        }
293
294 19
        if (!$resolverValue && !$resolved) {
295 1
            throw new \Exception(sprintf('Property "%s" not found in resolve result', $fieldAst->getName()));
296
        }
297
298 19
        return $resolverValue;
299
    }
300
301
    /**
302
     * @param $field     AbstractField
303
     * @param $query     Query
304
     *
305
     * @return array
306
     */
307 22
    protected function parseArgumentsValues(AbstractField $field, Query $query)
308
    {
309 22
        $args = [];
310 22
        foreach ($query->getArguments() as $argument) {
311 9
            if ($configArgument = $field->getConfig()->getArgument($argument->getName())) {
312 9
                $args[$argument->getName()] = $configArgument->getType()->parseValue($argument->getValue()->getValue());
313 9
            }
314 22
        }
315
316 22
        return $args;
317
    }
318
319
    /**
320
     * @param $query         Query|FragmentInterface
321
     * @param $queryType     AbstractObjectType|TypeInterface|Field|AbstractType
322
     * @param $resolvedValue mixed
323
     * @param $value         array
324
     *
325
     * @throws \Exception
326
     *
327
     * @return array
328
     */
329 20
    protected function processQueryFields($query, AbstractType $queryType, $resolvedValue, $value)
330
    {
331 20
        if ($queryType instanceof AbstractScalarType && !$query->hasFields()) {
332 1
            return $this->getOutputValue($queryType, $resolvedValue);
333
        }
334
335 20
        foreach ($query->getFields() as $fieldAst) {
336 20
            $fieldResolvedValue = null;
337
338 20
            if ($fieldAst instanceof FragmentInterface) {
339
                /** @var TypedFragmentReference $fragment */
340 3
                $fragment = $fieldAst;
341 3
                if ($fieldAst instanceof FragmentReference) {
342
                    /** @var Fragment $fragment */
343 2
                    $fragment = $this->executionContext->getRequest()->getFragment($fieldAst->getName());
344 2
                    $this->resolveValidator->assertValidFragmentForField($fragment, $fieldAst, $queryType);
345 3
                } elseif ($fragment->getTypeName() !== $queryType->getName()) {
346 1
                    continue;
347
                }
348
349 3
                $fragmentValue      = $this->processQueryFields($fragment, $queryType, $resolvedValue, $value);
350 3
                $fieldResolvedValue = is_array($fragmentValue) ? $fragmentValue : [];
351 3
            } else {
352 20
                $alias       = $fieldAst->getAlias() ?: $fieldAst->getName();
353 20
                $currentType = $queryType->getNullableType();
354
355 20
                if ($fieldAst->getName() == self::TYPE_NAME_QUERY) {
356 1
                    $fieldResolvedValue = [$alias => $queryType->getName()];
357 1
                } else {
358 20
                    if (!$this->resolveValidator->objectHasField($currentType, $fieldAst)) {
359 3
                        $fieldResolvedValue = null;
360 3
                    } else {
361 20
                        if ($fieldAst instanceof Query) {
362 10
                            $queryAst           = $currentType->getField($fieldAst->getName());
363 10
                            $fieldValue         = $queryAst ? $this->processQueryAST($fieldAst, $queryAst, $resolvedValue) : null;
364 10
                            $fieldResolvedValue = [$alias => $fieldValue];
365 20
                        } elseif ($fieldAst instanceof FieldAst) {
366
                            $fieldResolvedValue = [
367 19
                                $alias => $this->processFieldAST($fieldAst, $currentType->getField($fieldAst->getName()), $resolvedValue)
368 19
                            ];
369 19
                        }
370
                    }
371
372
373
                }
374
            }
375
376 20
            $value = $this->collectValue($value, $fieldResolvedValue);
377 20
        }
378
379 20
        return $value;
380
    }
381
382 19
    protected function getFieldValidatedValue(AbstractField $field, $value)
383
    {
384 19
        return ($this->resolveValidator->isValidValueForField($field, $value)) ? $this->getOutputValue($field->getType(), $value) : null;
385
    }
386
387 19
    protected function getOutputValue(AbstractType $type, $value)
388
    {
389 19
        return in_array($type->getKind(), [TypeMap::KIND_OBJECT, TypeMap::KIND_NON_NULL]) ? $value : $type->serialize($value);
390
    }
391
392 20
    protected function collectValue($value, $queryValue)
393
    {
394 20
        if ($queryValue && is_array($queryValue)) {
395 20
            $value = array_merge(is_array($value) ? $value : [], $queryValue);
396 20
        } else {
397 3
            $value = $queryValue;
398
        }
399
400 20
        return $value;
401
    }
402
403 24
    protected function introduceIntrospectionFields(AbstractSchema $schema)
404
    {
405 24
        $schemaField = new SchemaField();
406 24
        $schemaField->setSchema($schema);
407
408 24
        $schema->addQueryField($schemaField);
409 24
        $schema->addQueryField(new TypeDefinitionField());
410 24
    }
411
412 24
    public function getResponseData()
413
    {
414 24
        $result = [];
415
416 24
        if (!empty($this->data)) {
417 22
            $result['data'] = $this->data;
418 22
        }
419
420 24
        if ($this->executionContext->hasErrors()) {
421 7
            $result['errors'] = $this->executionContext->getErrorsArray();
422 7
        }
423
424 24
        return $result;
425
    }
426
427 1
    public function setMaxComplexity($max)
428
    {
429 1
        $this->maxComplexity = $max;
430 1
    }
431
432
    /**
433
     * @param AbstractType $queryType
434
     * @param AbstractType $mutationType
435
     * @param array        $reducers
436
     */
437 24
    protected function reduceQuery($queryType, $mutationType, array $reducers)
438
    {
439 24
        foreach ($reducers as $reducer) {
440 2
            foreach ($this->executionContext->getRequest()->getOperationsInOrder() as $operation) {
441 2
                $this->doVisit($operation, $operation instanceof Mutation ? $mutationType : $queryType, $reducer);
442 2
            }
443 24
        }
444 24
    }
445
446
    /**
447
     * @param Query                $query
448
     * @param AbstractType         $currentLevelSchema
449
     * @param AbstractQueryVisitor $reducer
450
     */
451 2
    protected function doVisit(Query $query, $currentLevelSchema, $reducer)
452
    {
453 2
        if (!($currentLevelSchema instanceof AbstractObjectType) || !$currentLevelSchema->hasField($query->getName())) {
454
            return;
455
        }
456
457 2
        if ($operationField = $currentLevelSchema->getField($query->getName())) {
458
459 2
            $coroutine = $this->walkQuery($query, $operationField);
460
461 2
            if ($results = $coroutine->current()) {
462 2
                $queryCost = 0;
463 2
                while ($results) {
464
                    // initial values come from advancing the generator via ->current, subsequent values come from ->send()
465 2
                    list($queryField, $astField, $childCost) = $results;
466
467
                    /**
468
                     * @var Query|FieldAst $queryField
469
                     * @var Field          $astField
470
                     */
471 2
                    $cost = $reducer->visit($queryField->getKeyValueArguments(), $astField->getConfig(), $childCost);
472 2
                    $queryCost += $cost;
473 2
                    $results = $coroutine->send($cost);
474 2
                }
475 2
            }
476 2
        }
477 2
    }
478
479
    /**
480
     * Coroutine to walk the query and schema in DFS manner and yield a tuple of (queryNode, schemaNode, childScore)
481
     *
482
     * childScore costs are accumulated via values sent into the coroutine.
483
     *
484
     * @param Query|Field|FragmentInterface $queryNode
485
     * @param AbstractField                 $currentLevelAST
486
     *
487
     * @return \Generator
488
     */
489 2
    protected function walkQuery($queryNode, AbstractField $currentLevelAST)
490
    {
491 2
        $childrenScore = 0;
492 2
        if (!($queryNode instanceof FieldAst)) {
493 2
            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...
494 2
                if ($queryField instanceof FragmentInterface) {
495 1
                    if ($queryField instanceof FragmentReference) {
496
                        $queryField = $this->executionContext->getRequest()->getFragment($queryField->getName());
497
                    }
498
                    // the next 7 lines are essentially equivalent to `yield from $this->walkQuery(...)` in PHP7.
499
                    // for backwards compatibility this is equivalent.
500
                    // This pattern is repeated multiple times in this function, and unfortunately cannot be extracted or
501
                    // made less verbose.
502 1
                    $gen  = $this->walkQuery($queryField, $currentLevelAST);
0 ignored issues
show
Bug introduced by
It seems like $queryField defined by $this->executionContext-...$queryField->getName()) on line 496 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...
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
                } else {
510 2
                    $fieldType = $currentLevelAST->getType()->getNamedType();
511 2
                    if ($fieldType instanceof AbstractUnionType) {
512 1
                        foreach ($fieldType->getTypes() as $unionFieldType) {
513 1 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...
514 1
                                $gen  = $this->walkQuery($queryField, $fieldAst);
515 1
                                $next = $gen->current();
516 1
                                while ($next) {
517 1
                                    $received = (yield $next);
518 1
                                    $childrenScore += (int)$received;
519 1
                                    $next = $gen->send($received);
520 1
                                }
521 1
                            }
522 1
                        }
523 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...
524 1
                        $gen  = $this->walkQuery($queryField, $fieldAst);
525 1
                        $next = $gen->current();
526 1
                        while ($next) {
527 1
                            $received = (yield $next);
528 1
                            $childrenScore += (int)$received;
529 1
                            $next = $gen->send($received);
530 1
                        }
531 1
                    }
532
                }
533 2
            }
534 2
        }
535
        // sanity check.  don't yield fragments; they don't contribute to cost
536 2
        if ($queryNode instanceof Query || $queryNode instanceof FieldAst) {
537 2
            yield [$queryNode, $currentLevelAST, $childrenScore];
538 2
        }
539 2
    }
540
}
541