ArgumentMiddleware::process()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 11
c 1
b 0
f 1
nc 5
nop 2
dl 0
loc 21
ccs 13
cts 13
cp 1
crap 5
rs 9.6111
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