InputObjectFieldMiddleware   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 31
ccs 15
cts 15
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A process() 0 22 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\InputObjectFieldResolver\Middleware;
6
7
use Andi\GraphQL\Common\LazyType;
8
use Andi\GraphQL\Definition\Field\DefaultValueAwareInterface;
9
use Andi\GraphQL\Definition\Field\DeprecationReasonAwareInterface;
10
use Andi\GraphQL\Definition\Field\InputObjectFieldInterface;
11
use Andi\GraphQL\InputObjectFieldResolver\InputObjectFieldResolverInterface;
12
use Andi\GraphQL\TypeRegistryInterface;
13
use GraphQL\Type\Definition as Webonyx;
14
15
/**
16
 * @see Webonyx\InputObjectField
17
 *
18
 * @phpstan-import-type InputObjectFieldConfig from Webonyx\InputObjectField
19
 */
20
final class InputObjectFieldMiddleware implements MiddlewareInterface
21
{
22
    public const PRIORITY = 2048;
23
24 4
    public function __construct(
25
        private readonly TypeRegistryInterface $typeRegistry,
26
    ) {
27 4
    }
28
29 3
    public function process(mixed $field, InputObjectFieldResolverInterface $fieldResolver): Webonyx\InputObjectField
30
    {
31 3
        if (! $field instanceof InputObjectFieldInterface) {
32 1
            return $fieldResolver->resolve($field);
33
        }
34
35
        /** @var InputObjectFieldConfig $config */
36 2
        $config = [
37 2
            'name' => $field->getName(),
38 2
            'description' => $field->getDescription(),
39 2
            'type' => new LazyType($field, $this->typeRegistry),
40 2
        ];
41
42 2
        if ($field instanceof DeprecationReasonAwareInterface) {
43 2
            $config['deprecationReason'] = $field->getDeprecationReason();
44
        }
45
46 2
        if ($field instanceof DefaultValueAwareInterface && $field->hasDefaultValue()) {
47 1
            $config['defaultValue'] = $field->getDefaultValue();
48
        }
49
50 2
        return new Webonyx\InputObjectField($config);
0 ignored issues
show
Bug introduced by
$config of type Andi\GraphQL\InputObject...\InputObjectFieldConfig is incompatible with the type array expected by parameter $config of GraphQL\Type\Definition\...ectField::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
        return new Webonyx\InputObjectField(/** @scrutinizer ignore-type */ $config);
Loading history...
51
    }
52
}
53