InputObjectType::extractFields()   A
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 6
eloc 9
c 1
b 0
f 1
nc 10
nop 0
dl 0
loc 17
ccs 0
cts 10
cp 0
crap 42
rs 9.2222
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\WebonyxType;
6
7
use Andi\GraphQL\InputObjectFieldResolver\InputObjectFieldResolverInterface;
8
use Andi\GraphQL\Type\DynamicObjectTypeInterface;
9
use GraphQL\Type\Definition as Webonyx;
10
11
/**
12
 * @see Webonyx\InputObjectType
13
 *
14
 * @phpstan-import-type InputObjectConfig from Webonyx\InputObjectType
15
 */
16
class InputObjectType extends Webonyx\InputObjectType implements DynamicObjectTypeInterface
17
{
18
    /**
19
     * @var callable|iterable
20
     */
21
    private readonly mixed $nativeFields;
22
23
    private array $additionalFields = [];
24
25
    /**
26
     * @param InputObjectConfig $config
0 ignored issues
show
Bug introduced by
The type Andi\GraphQL\WebonyxType\InputObjectConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
     * @param InputObjectFieldResolverInterface $inputObjectFieldResolver
28
     */
29
    public function __construct(
30
        array $config,
31
        private readonly InputObjectFieldResolverInterface $inputObjectFieldResolver,
32
    ) {
33
        if (isset($config['fields'])) {
34
            $this->nativeFields = $config['fields'];
0 ignored issues
show
Bug introduced by
The property nativeFields is declared read-only in Andi\GraphQL\WebonyxType\InputObjectType.
Loading history...
35
        }
36
37
        $config['fields'] = $this->extractFields(...);
38
39
        parent::__construct($config);
40
    }
41
42
    public function addAdditionalField(mixed $field): static
43
    {
44
        $this->additionalFields[] = $field;
45
46
        return $this;
47
    }
48
49
    private function extractFields(): iterable
0 ignored issues
show
Unused Code introduced by
The method extractFields() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
50
    {
51
        /** @psalm-suppress RedundantPropertyInitializationCheck */
52
        if (isset($this->nativeFields)) {
53
            $fields = \is_callable($this->nativeFields)
54
                ? \call_user_func($this->nativeFields)
55
                : $this->nativeFields;
56
57
            if (\is_iterable($fields)) {
58
                foreach ($fields as $field) {
59
                    yield $this->inputObjectFieldResolver->resolve($field);
60
                }
61
            }
62
        }
63
64
        foreach ($this->additionalFields as $field) {
65
            yield $this->inputObjectFieldResolver->resolve($field);
66
        }
67
    }
68
}
69