buildField()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 11
ccs 9
cts 9
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\ObjectFieldResolver\Middleware;
6
7
use Andi\GraphQL\ArgumentResolver\ArgumentResolverInterface;
8
use Andi\GraphQL\Field\OuterObjectField;
9
use Andi\GraphQL\TypeRegistryInterface;
10
use GraphQL\Type\Definition as Webonyx;
11
use ReflectionMethod;
12
use Spiral\Attributes\ReaderInterface;
13
use Spiral\Core\InvokerInterface;
14
use Spiral\Core\ScopeInterface;
15
16
abstract class AbstractOuterObjectFieldByReflectionMethodMiddleware extends AbstractFieldByReflectionMethodMiddleware
17
{
18 7
    public function __construct(
19
        ReaderInterface $reader,
20
        TypeRegistryInterface $typeRegistry,
21
        ArgumentResolverInterface $argumentResolver,
22
        private readonly ScopeInterface $scope,
23
        private readonly InvokerInterface $invoker,
24
    ) {
25 7
        parent::__construct($reader, $typeRegistry, $argumentResolver);
26
    }
27
28 3
    protected function buildField(array $config, ReflectionMethod $method): Webonyx\FieldDefinition
29
    {
30 3
        $config['args'] = \iterator_to_array($iterator = $this->getFieldArguments($method));
31
32 3
        return new OuterObjectField(
33 3
            $config,
34 3
            $method->getDeclaringClass()->getName(),
35 3
            $method->getName(),
36 3
            $iterator->getReturn(),
37 3
            $this->scope,
38 3
            $this->invoker,
39 3
        );
40
    }
41
}
42