LazyTypeResolver::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
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\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