LazyType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 28
ccs 13
cts 13
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 20 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Common;
6
7
use Andi\GraphQL\Definition\Field\TypeAwareInterface;
8
use Andi\GraphQL\TypeRegistryInterface;
9
use GraphQL\Type\Definition as Webonyx;
10
11
final class LazyType
12
{
13 6
    public function __construct(
14
        private readonly TypeAwareInterface $type,
15
        private readonly TypeRegistryInterface $typeRegistry,
16
    ) {
17 6
    }
18
19 5
    public function __invoke(): Webonyx\Type
20
    {
21 5
        $type = $this->typeRegistry->get($this->type->getType());
22
23 5
        $mode = $this->type->getMode();
24
25 5
        if (TypeAwareInterface::ITEM_IS_REQUIRED === (TypeAwareInterface::ITEM_IS_REQUIRED & $mode)) {
26 2
            \assert($type instanceof Webonyx\NullableType);
27 2
            $type = Webonyx\Type::nonNull($type);
28
        }
29
30 5
        if (TypeAwareInterface::IS_LIST === (TypeAwareInterface::IS_LIST & $mode)) {
31 3
            $type = Webonyx\Type::listOf($type);
32
        }
33
34 5
        if (TypeAwareInterface::IS_REQUIRED === (TypeAwareInterface::IS_REQUIRED & $mode)) {
35 2
            $type = Webonyx\Type::nonNull($type);
36
        }
37
38 5
        return $type;
39
    }
40
}
41