ValueResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A __invoke() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Spiral\Common;
6
7
use GraphQL\Language\AST\DocumentNode;
8
use GraphQL\Server\OperationParams;
9
use Spiral\Core\InvokerInterface;
10
use Spiral\Core\ScopeInterface;
11
12
final class ValueResolver
13
{
14
    private readonly \Closure $factoryFn;
15
16 4
    public function __construct(
17
        private readonly ScopeInterface $scope,
18
        private readonly InvokerInterface $invoker,
19
        callable $factory,
20
    ) {
21 4
        $this->factoryFn = $factory instanceof \Closure
0 ignored issues
show
Bug introduced by
The property factoryFn is declared read-only in Andi\GraphQL\Spiral\Common\ValueResolver.
Loading history...
22 2
            ? $factory
23 2
            : $factory(...);
24
    }
25
26 3
    public function __invoke(OperationParams $params, DocumentNode $doc, string $operationType): mixed
27
    {
28 3
        return $this->scope->runScope(
29 3
            [OperationParams::class => $params, DocumentNode::class => $doc],
30 3
            fn () => $this->invoker->invoke($this->factoryFn, ['operationType' => $operationType]),
31 3
        );
32
    }
33
}
34