Completed
Push — master ( 5882cd...69f7ce )
by Alexandr
03:28
created

Processor::processAstFieldQuery()   C

Complexity

Conditions 11
Paths 9

Size

Total Lines 59
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 26.125

Importance

Changes 4
Bugs 2 Features 0
Metric Value
c 4
b 2
f 0
dl 0
loc 59
rs 6.3545
ccs 19
cts 38
cp 0.5
cc 11
eloc 37
nc 9
nop 3
crap 26.125

How to fix   Long Method    Complexity   

Long Method

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:

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;
11
12
use Youshido\GraphQL\Introspection\QueryType;
13
use Youshido\GraphQL\Introspection\SchemaType;
14
use Youshido\GraphQL\Introspection\TypeDefinitionType;
15
use Youshido\GraphQL\Parser\Ast\FragmentReference;
16
use Youshido\GraphQL\Parser\Ast\Mutation;
17
use Youshido\GraphQL\Parser\Ast\Query;
18
use Youshido\GraphQL\Parser\Ast\TypedFragmentReference;
19
use Youshido\GraphQL\Parser\Parser;
20
use Youshido\GraphQL\Type\AbstractType;
21
use Youshido\GraphQL\Type\Field\Field;
22
use Youshido\GraphQL\Type\Object\AbstractEnumType;
23
use Youshido\GraphQL\Type\Object\AbstractInterfaceType;
24
use Youshido\GraphQL\Type\Object\ObjectType;
25
use Youshido\GraphQL\Type\Scalar\AbstractScalarType;
26
use Youshido\GraphQL\Type\TypeInterface;
27
use Youshido\GraphQL\Type\TypeMap;
28
use Youshido\GraphQL\Parser\Ast\Field as AstField;
29
use Youshido\GraphQL\Validator\ErrorContainer\ErrorContainerTrait;
30
use Youshido\GraphQL\Validator\Exception\ConfigurationException;
31
use Youshido\GraphQL\Validator\Exception\ResolveException;
32
use Youshido\GraphQL\Validator\ResolveValidator\ResolveValidator;
33
use Youshido\GraphQL\Validator\ResolveValidator\ResolveValidatorInterface;
34
use Youshido\GraphQL\Validator\SchemaValidator\SchemaValidator;
35
36
class Processor
37
{
38
    use ErrorContainerTrait;
39
40
    const TYPE_NAME_QUERY = '__typename';
41
42
    /** @var  array */
43
    protected $data;
44
45
    /** @var ResolveValidatorInterface */
46
    protected $resolveValidator;
47
48
    /** @var SchemaValidator */
49
    protected $schemaValidator;
50
51
    /** @var AbstractSchema */
52
    protected $schema;
53
54
    /** @var Request */
55
    protected $request;
56
57 19
    public function __construct()
58
    {
59 19
        $this->resolveValidator = new ResolveValidator();
60 19
        $this->schemaValidator  = new SchemaValidator();
61 19
    }
62
63 19
    public function setSchema(AbstractSchema $schema)
64
    {
65 19
        if (!$this->schemaValidator->validate($schema)) {
66
            $this->mergeErrors($this->schemaValidator);
67
68
            return;
69
        }
70
71 19
        $this->schema = $schema;
72
73 19
        $__schema = new SchemaType();
74 19
        $__schema->setSchema($schema);
75
76 19
        $__type = new TypeDefinitionType();
77
78 19
        $this->schema->addQuery('__schema', $__schema);
79 19
        $this->schema->addQuery('__type', $__type);
80 19
    }
81
82 19
    public function processRequest($payload, $variables = [])
83
    {
84 19
        if ($this->hasErrors()) return $this;
85
86 19
        $this->data = [];
87
88
        try {
89 19
            $this->parseAndCreateRequest($payload, $variables);
90
91 19
            foreach ($this->request->getQueries() as $query) {
92 19
                if ($queryResult = $this->executeQuery($query, $this->getSchema()->getQueryType())) {
93 17
                    $this->data = array_merge($this->data, $queryResult);
94 17
                };
95 19
            }
96
97 19
            foreach ($this->request->getMutations() as $mutation) {
98
                if ($mutationResult = $this->executeMutation($mutation, $this->getSchema()->getMutationType())) {
99
                    $this->data = array_merge($this->data, $mutationResult);
100
                }
101 19
            }
102
103 19
        } catch (\Exception $e) {
104
            $this->resolveValidator->clearErrors();
105
106 1
            $this->resolveValidator->addError($e);
107
        }
108
109 19
        return $this;
110
    }
111
112 19
    protected function parseAndCreateRequest($query, $variables = [])
113
    {
114 19
        $parser = new Parser();
115
116 19
        $data = $parser->parse($query);
117
118 19
        $this->request = new Request($data);
119 19
        $this->request->setVariables($variables);
120 19
    }
121
122
    /**
123
     * @param Query|Field          $query
124
     * @param ObjectType|QueryType $currentLevelSchema
125
     * @param null                 $contextValue
126
     * @return array|bool|mixed
127
     */
128 19
    protected function executeQuery($query, $currentLevelSchema, $contextValue = null)
129
    {
130 19
        if (!$this->resolveValidator->checkFieldExist($currentLevelSchema, $query)) {
131
            return null;
132
        }
133
134
        /** @var Field $field */
135 19
        $field = $currentLevelSchema->getField($query->getName());
0 ignored issues
show
Bug introduced by
The method getName does only exist in Youshido\GraphQL\Parser\Ast\Query, but not in Youshido\GraphQL\Type\Field\Field.

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...
136 19
        $alias = $query->getAlias() ?: $query->getName();
0 ignored issues
show
Bug introduced by
The method getAlias does only exist in Youshido\GraphQL\Parser\Ast\Query, but not in Youshido\GraphQL\Type\Field\Field.

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...
137
138 19
        if ($query instanceof AstField) {
139 17
            $value = $this->processAstFieldQuery($query, $contextValue, $field);
140 17
        } else {
141 19
            if (!$this->resolveValidator->validateArguments($field, $query, $this->request)) {
142 2
                return null;
143
            }
144
145 17
            $value = $this->processFieldTypeQuery($query, $contextValue, $field);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $value is correct as $this->processFieldTypeQ... $contextValue, $field) (which targets Youshido\GraphQL\Process...processFieldTypeQuery()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
146
147
        }
148
149 17
        return [$alias => $value];
150
    }
151
152
    /**
153
     * @param Mutation   $mutation
154
     * @param ObjectType $currentLevelSchema
155
     * @return array|null
156
     * @throws ConfigurationException
157
     */
158
    protected function executeMutation(Mutation $mutation, $currentLevelSchema)
159
    {
160
        if (!$currentLevelSchema) throw new ConfigurationException('There is no mutation ' . $mutation->getName());
161
162
        if (!$this->resolveValidator->checkFieldExist($currentLevelSchema, $mutation)) {
163
            return null;
164
        }
165
166
        /** @var Field $field */
167
        $field = $currentLevelSchema->getConfig()->getField($mutation->getName());
168
        $alias = $mutation->getAlias() ?: $mutation->getName();
169
170
        if (!$this->resolveValidator->validateArguments($field, $mutation, $this->request)) {
171
            return null;
172
        }
173
174
        $resolvedValue = $this->resolveValue($field, null, $mutation);
175
176 View Code Duplication
        if (!$this->resolveValidator->validateResolvedValue($resolvedValue, $field->getType())) {
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...
177
            $this->resolveValidator->addError(new ResolveException(sprintf('Not valid resolved value for mutation "%s"', $field->getType()->getName())));
178
179
            return [$alias => null];
180
        }
181
182
        $value = $resolvedValue;
183
        if ($mutation->hasFields()) {
184
            if ($field->getType()->isAbstractType()) {
185
                $outputType = $field->getType()->getConfig()->resolveType($resolvedValue);
0 ignored issues
show
Documentation Bug introduced by
The method resolveType does not exist on object<Youshido\GraphQL\...bject\ObjectTypeConfig>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
186
            } else {
187
                /** @var AbstractType $outputType */
188
                $outputType = $field->getType();
189
            }
190
191
            $value = $this->collectListOrSingleValue($outputType, $resolvedValue, $mutation);
192
        }
193
194
        return [$alias => $value];
195
    }
196
197
    /**
198
     * @param AstField $astField
199
     * @param mixed    $contextValue
200
     * @param Field    $field
201
     * @return array|mixed|null
202
     * @throws \Exception
203
     */
204 17
    protected function processAstFieldQuery(AstField $astField, $contextValue, Field $field)
205
    {
206 17
        $value            = null;
207 17
        $preResolvedValue = $this->getPreResolvedValue($contextValue, $astField, $field);
208
209 17
        if ($field->getConfig()->getType()->getKind() == TypeMap::KIND_LIST) {
210 1
            if (!is_array($preResolvedValue)) {
211
                $this->resolveValidator->addError(new ResolveException('Not valid resolve value for list type'));
212
213
                return null;
214
            }
215
216 1
            $listValue = [];
217 1
            foreach ($preResolvedValue as $resolvedValueItem) {
218
                /** @var TypeInterface $type */
219 1
                $type = $field->getType()->getConfig()->getItem();
0 ignored issues
show
Documentation Bug introduced by
The method getItem does not exist on object<Youshido\GraphQL\...bject\ObjectTypeConfig>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
220
221 1
                if ($type->getKind() == TypeMap::KIND_ENUM) {
222
                    /** @var $type AbstractEnumType */
223 1
                    if (!$type->isValidValue($resolvedValueItem)) {
224
                        $this->resolveValidator->addError(new ResolveException('Not valid value for enum type'));
225
226
                        $listValue = null;
227
                        break;
228
                    }
229
230 1
                    $listValue[] = $type->resolve($resolvedValueItem);
231 1
                } else {
232
                    /** @var AbstractScalarType $type */
233
                    $listValue[] = $type->serialize($preResolvedValue);
234
                }
235 1
            }
236
237 1
            $value = $listValue;
238 1
        } else {
239 17
            if ($field->getType()->getKind() == TypeMap::KIND_ENUM) {
240
                if (!$field->getType()->isValidValue($preResolvedValue)) {
241
                    $this->resolveValidator->addError(new ResolveException(sprintf('Not valid value for %s type', ($field->getType()->getKind()))));
242
                    $value = null;
243
                } else {
244
                    $value = $preResolvedValue;
245
                    /** $field->getType()->resolve($preResolvedValue); */
246
                }
247 17
            } elseif ($field->getType()->getKind() == TypeMap::KIND_NON_NULL) {
248
                if (!$field->getType()->isValidValue($preResolvedValue)) {
249
                    $this->resolveValidator->addError(new ResolveException(sprintf('Cannot return null for non-nullable field %s', $astField->getName() . '.' . $field->getName())));
0 ignored issues
show
Bug introduced by
The method getName() does not exist on Youshido\GraphQL\Type\Field\Field. Did you maybe mean getNamedType()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
250
                } elseif (!$field->getType()->getNullableType()->isValidValue($preResolvedValue)) {
251
                    $this->resolveValidator->addError(new ResolveException(sprintf('Not valid value for %s field %s', $field->getType()->getNullableType()->getKind(), $field->getName())));
0 ignored issues
show
Bug introduced by
The method getName() does not exist on Youshido\GraphQL\Type\Field\Field. Did you maybe mean getNamedType()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
252
                    $value = null;
253
                } else {
254
                    $value = $preResolvedValue;
255
                }
256
            } else {
257 17
                $value = $field->getType()->serialize($preResolvedValue);
258
            }
259
        }
260
261 17
        return $value;
262
    }
263
264
    /**
265
     * @param       $query
266
     * @param mixed $contextValue
267
     * @param Field $field
268
     * @return null
269
     * @throws \Exception
270
     */
271 17
    protected function processFieldTypeQuery($query, $contextValue, $field)
272
    {
273 17
        if (!($resolvedValue = $this->resolveValue($field, $contextValue, $query))) {
274 3
            return $resolvedValue;
275
        }
276
277 17 View Code Duplication
        if (!$this->resolveValidator->validateResolvedValue($resolvedValue, $field->getType())) {
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...
278
            $this->resolveValidator->addError(new ResolveException(sprintf('Not valid resolved value for query "%s"', $field->getType()->getName())));
279
280
            return null;
281
        }
282
283 17
        return $this->collectListOrSingleValue($field->getType(), $resolvedValue, $query);
284
    }
285
286
    /**
287
     * @param AbstractType   $fieldType
288
     * @param mixed          $resolvedValue
289
     * @param Query|Mutation $query
290
     * @return array|mixed
291
     * @throws \Exception
292
     */
293 17
    protected function collectListOrSingleValue(AbstractType $fieldType, $resolvedValue, $query)
294
    {
295 17
        $value = [];
296 17
        if ($fieldType->getKind() == TypeMap::KIND_LIST) {
297 7
            foreach ($resolvedValue as $resolvedValueItem) {
298 7
                $value[]   = [];
299 7
                $index     = count($value) - 1;
300 7
                $namedType = $fieldType->getNamedType();
301
302 7
                if ($namedType->isAbstractType()) {
303 4
                    $resolvedType = $namedType->getConfig()->resolveType($resolvedValueItem);
0 ignored issues
show
Documentation Bug introduced by
The method resolveType does not exist on object<Youshido\GraphQL\...bject\ObjectTypeConfig>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
304 4
                    if ($namedType instanceof AbstractInterfaceType) {
305 2
                        $this->resolveValidator->assertTypeImplementsInterface($resolvedType, $namedType);
306 2
                    }
307 4
                    $namedType = $resolvedType;
308 4
                }
309
310 7
                $value[$index] = $this->processQueryFields($query, $namedType, $resolvedValueItem, $value[$index]);
311 7
            }
312 7
        } else {
313 15
            $value = $this->processQueryFields($query, $fieldType, $resolvedValue, $value);
314
        }
315
316 17
        return $value;
317
    }
318
319
    /**
320
     * @param          $value
321
     * @param AstField $astField
322
     * @param Field    $field
323
     *
324
     * @throws \Exception
325
     *
326
     * @return mixed
327
     */
328 17
    protected function getPreResolvedValue($value, AstField $astField, Field $field)
329
    {
330 17
        $resolved      = false;
331 17
        $resolverValue = null;
332
333 17
        if (is_array($value) && array_key_exists($astField->getName(), $value)) {
334 12
            $resolverValue = $value[$astField->getName()];
335 12
            $resolved      = true;
336 17
        } elseif (is_object($value)) {
337
            try {
338 5
                $resolverValue = $this->getPropertyValue($value, $astField->getName());
339 5
                $resolved      = true;
340 5
            } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
341
            }
342 5
        } elseif ($field->getNamedType()->getKind() == TypeMap::KIND_SCALAR) {
343
            $resolved = true;
344
        }
345
346 17
        if ($resolved) {
347 17
            if ($field->getConfig() && ($field->getConfig()->issetResolve())) {
348 1
                $resolverValue = $field->resolve($resolverValue, $astField->getKeyValueArguments(), $field->getType());
349 1
            }
350
351 17
            return $resolverValue;
352
        }
353
354
        throw new \Exception(sprintf('Property "%s" not found in resolve result', $astField->getName()));
355
    }
356
357 5
    protected function getPropertyValue($data, $path)
358
    {
359 5
        if (is_object($data)) {
360 5
            $getter = 'get' . $this->classify($path);
361
362 5
            return is_callable([$data, $getter]) ? $data->$getter() : null;
363
        } elseif (is_array($data)) {
364
            return array_key_exists($path, $data) ? $data[$path] : null;
365
        }
366
367
        return null;
368
    }
369
370 5
    protected function classify($text)
371
    {
372 5
        $text       = explode(' ', str_replace(['_', '/', '-', '.'], ' ', $text));
373 5
        $textLength = count($text);
374 5
        for ($i = 0; $i < $textLength; $i++) {
375 5
            $text[$i] = ucfirst($text[$i]);
376 5
        }
377 5
        $text = ucfirst(implode('', $text));
378
379 5
        return $text;
380
    }
381
382
    /**
383
     * @param Field $field
384
     * @param mixed $contextValue
385
     * @param Query $query
386
     *
387
     * @return mixed
388
     */
389 17
    protected function resolveValue($field, $contextValue, $query)
390
    {
391 17
        $resolvedValue = $field->resolve($contextValue, $this->parseArgumentsValues($field, $query), $field->getType());
392
393 17
        if ($field->getType()->isAbstractType()) {
394 6
            $resolvedType = $field->getType()->resolveType($resolvedValue);
0 ignored issues
show
Documentation Bug introduced by
The method resolveType does not exist on object<Youshido\GraphQL\...ect\AbstractObjectType>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
395 6
            $field->setType($resolvedType);
396 6
        }
397
398 17
        return $resolvedValue;
399
    }
400
401
    /**
402
     * @param $field     Field
403
     * @param $query     Query
404
     *
405
     * @return array
406
     */
407 17
    public function parseArgumentsValues($field, $query)
408
    {
409 17
        if ($query instanceof \Youshido\GraphQL\Parser\Ast\Field) {
410
            return [];
411
        }
412
413 17
        $args = [];
414 17
        foreach ($query->getArguments() as $argument) {
415 5
            if ($configArgument = $field->getConfig()->getArgument($argument->getName())) {
416 5
                $args[$argument->getName()] = $configArgument->getType()->parseValue($argument->getValue()->getValue());
417 5
            }
418 17
        }
419
420 17
        return $args;
421
    }
422
423
    /**
424
     * @param $query         Query
425
     * @param $queryType     ObjectType|TypeInterface|Field
426
     * @param $resolvedValue mixed
427
     * @param $value         array
428
     *
429
     * @throws \Exception
430
     *
431
     * @return array
432
     */
433 17
    protected function processQueryFields($query, $queryType, $resolvedValue, $value)
434
    {
435 17
        foreach ($query->getFields() as $field) {
436 17
            if ($field instanceof FragmentReference) {
437 1
                if (!$fragment = $this->request->getFragment($field->getName())) {
438
                    throw new \Exception(sprintf('Fragment reference "%s" not found', $field->getName()));
439
                }
440
441 1
                if ($fragment->getModel() !== $queryType->getName()) {
442
                    throw new \Exception(sprintf('Fragment reference "%s" not found on model "%s"', $field->getName(), $queryType->getName()));
443
                }
444
445 1
                foreach ($fragment->getFields() as $fragmentField) {
446 1
                    $value = $this->collectValue($value, $this->executeQuery($fragmentField, $queryType, $resolvedValue));
447 1
                }
448 17
            } elseif ($field instanceof TypedFragmentReference) {
449 2
                if ($field->getTypeName() !== $queryType->getName()) {
450 1
                    continue;
451
                }
452
453 2
                foreach ($field->getFields() as $fragmentField) {
454 2
                    $value = $this->collectValue($value, $this->executeQuery($fragmentField, $queryType, $resolvedValue));
0 ignored issues
show
Documentation introduced by
$fragmentField is of type object<Youshido\GraphQL\Parser\Ast\Field>, but the function expects a object<Youshido\GraphQL\...aphQL\Type\Field\Field>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
455 2
                }
456 17
            } elseif ($field->getName() == self::TYPE_NAME_QUERY) {
457 1
                $value = $this->collectValue($value, [$field->getAlias() ?: $field->getName() => $queryType->getName()]);
458 1
            } else {
459 17
                $value = $this->collectValue($value, $this->executeQuery($field, $queryType, $resolvedValue));
460
            }
461 17
        }
462
463 17
        return $value;
464
    }
465
466 17
    protected function collectValue($value, $queryValue)
467
    {
468 17
        if ($queryValue && is_array($queryValue)) {
469 17
            $value = array_merge(is_array($value) ? $value : [], $queryValue);
470 17
        } else {
471
            $value = $queryValue;
472
        }
473
474 17
        return $value;
475
    }
476
477 19
    public function getSchema()
478
    {
479 19
        return $this->schema;
480
    }
481
482 19
    public function getResponseData()
483
    {
484 19
        $result = [];
485
486 19
        if (!empty($this->data)) {
487 17
            $result['data'] = $this->data;
488 17
        }
489
490 19
        $this->mergeErrors($this->resolveValidator);
0 ignored issues
show
Documentation introduced by
$this->resolveValidator is of type object<Youshido\GraphQL\...olveValidatorInterface>, but the function expects a object<Youshido\GraphQL\...rrorContainerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
491 19
        if ($this->hasErrors()) {
492 2
            $result['errors'] = $this->getErrorsArray();
493 2
        }
494 19
        $this->clearErrors();
495 19
        $this->resolveValidator->clearErrors();
496 19
        $this->schemaValidator->clearErrors();
497
498 19
        return $result;
499
    }
500
}
501