ArgumentMiddleware   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
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 30
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 21 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\ArgumentResolver\Middleware;
6
7
use Andi\GraphQL\ArgumentResolver\ArgumentResolverInterface;
8
use Andi\GraphQL\Common\LazyType;
9
use Andi\GraphQL\Definition\Field\ArgumentInterface;
10
use Andi\GraphQL\Definition\Field\DefaultValueAwareInterface;
11
use Andi\GraphQL\Definition\Field\DeprecationReasonAwareInterface;
12
use Andi\GraphQL\TypeRegistryInterface;
13
14
final class ArgumentMiddleware implements MiddlewareInterface
15
{
16
    public const PRIORITY = 2048;
17
18 7
    public function __construct(
19
        private readonly TypeRegistryInterface $typeRegistry,
20
    ) {
21 7
    }
22
23 6
    public function process(mixed $argument, ArgumentResolverInterface $argumentResolver): array
24
    {
25 6
        if (! $argument instanceof ArgumentInterface) {
26 1
            return $argumentResolver->resolve($argument);
27
        }
28
29 5
        $config = [
30 5
            'name' => $argument->getName(),
31 5
            'description' => $argument->getDescription(),
32 5
            'type' => new LazyType($argument, $this->typeRegistry),
33 5
        ];
34
35 5
        if ($argument instanceof DeprecationReasonAwareInterface) {
36 2
            $config['deprecationReason'] = $argument->getDeprecationReason();
37
        }
38
39 5
        if ($argument instanceof DefaultValueAwareInterface && $argument->hasDefaultValue()) {
40 2
            $config['defaultValue'] = $argument->getDefaultValue();
41
        }
42
43 5
        return $config;
44
    }
45
}
46