LazyType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
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