AttributedQueryFieldListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A finalize() 0 6 3
A __construct() 0 6 1
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