LazyTypeResolver   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 21
ccs 4
cts 4
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Common;
6
7
use Andi\GraphQL\TypeRegistryInterface;
8
use GraphQL\Type\Definition as Webonyx;
9
10
final class LazyTypeResolver
11
{
12
    /**
13
     * @var callable(mixed, mixed, Webonyx\ResolveInfo): ?string
14
     */
15
    private readonly mixed $type;
16
17
    /**
18
     * @param callable(mixed, mixed, Webonyx\ResolveInfo): ?string $type
19
     * @param TypeRegistryInterface $typeRegistry
20
     */
21 3
    public function __construct(
22
        callable $type,
23
        private readonly TypeRegistryInterface $typeRegistry,
24
    ) {
25 3
        $this->type = $type;
0 ignored issues
show
Bug introduced by
The property type is declared read-only in Andi\GraphQL\Common\LazyTypeResolver.
Loading history...
26
    }
27
28 2
    public function __invoke(mixed $value, mixed $context, Webonyx\ResolveInfo $info): ?Webonyx\ObjectType
29
    {
30 2
        return $this->typeRegistry->get(\call_user_func($this->type, $value, $context, $info));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->typeRegist...alue, $context, $info)) returns the type GraphQL\Type\Definition\...pe\Definition\NamedType which includes types incompatible with the type-hinted return GraphQL\Type\Definition\ObjectType|null.
Loading history...
31
    }
32
}
33