ValueResolver::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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