AttributedQueryFieldListener::finalize()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 3
eloc 4
c 2
b 1
f 1
nc 3
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Spiral\Listener;
6
7
use Andi\GraphQL\Attribute\QueryField;
8
use Andi\GraphQL\Spiral\Config\GraphQLConfig;
9
use Andi\GraphQL\Type\DynamicObjectTypeInterface;
10
use Andi\GraphQL\TypeRegistryInterface;
11
use Spiral\Attributes\ReaderInterface;
12
use Spiral\Tokenizer\Attribute\TargetAttribute;
13
14
#[TargetAttribute(QueryField::class)]
15
final class AttributedQueryFieldListener extends AbstractAdditionalFieldListener
16
{
17
    protected string $attribute = QueryField::class;
18
19 3
    public function __construct(
20
        ReaderInterface $reader,
21
        TypeRegistryInterface $typeRegistry,
22
        private readonly GraphQLConfig $config,
23
    ) {
24 3
        parent::__construct($reader, $typeRegistry);
25
    }
26
27 2
    public function finalize(): void
28
    {
29 2
        $query = $this->typeRegistry->get($this->config->getQueryType());
30 2
        if ($query instanceof DynamicObjectTypeInterface) {
31 2
            foreach ($this->methods as $method) {
32 1
                $query->addAdditionalField($method);
33
            }
34
        }
35
    }
36
}
37