ObjectFieldResolver::resolve()   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 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
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\ObjectFieldResolver;
6
7
use Andi\GraphQL\ObjectFieldResolver\Middleware\MiddlewareInterface;
8
use Andi\GraphQL\ObjectFieldResolver\Middleware\Next;
9
use Andi\GraphQL\ObjectFieldResolver\Middleware\PipelineInterface;
10
use GraphQL\Type\Definition as Webonyx;
11
use SplPriorityQueue;
12
13
final class ObjectFieldResolver implements PipelineInterface
14
{
15
    private SplPriorityQueue $pipeline;
16
17
    private int $secondPriority = \PHP_INT_MAX;
18
19 5
    public function __construct()
20
    {
21 5
        $this->pipeline = new SplPriorityQueue();
22
    }
23
24 1
    public function __clone()
25
    {
26 1
        $this->pipeline = clone $this->pipeline;
27
    }
28
29 4
    public function resolve(mixed $field): Webonyx\FieldDefinition
30
    {
31 4
        return (new Next($this->pipeline, new CantResolveObjectFieldResolver()))->resolve($field);
32
    }
33
34 3
    public function pipe(MiddlewareInterface $middleware, int $priority = 0): void
35
    {
36 3
        $this->pipeline->insert($middleware, [$priority, $this->secondPriority--]);
37
    }
38
}
39