AdditionalFieldListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A finalize() 0 8 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Spiral\Listener;
6
7
use Andi\GraphQL\Attribute\AdditionalField;
8
use Andi\GraphQL\Common\ReflectionMethodWithAttribute;
9
use Andi\GraphQL\Type\DynamicObjectTypeInterface;
10
use Spiral\Tokenizer\Attribute\TargetAttribute;
11
12
#[TargetAttribute(AdditionalField::class)]
13
final class AdditionalFieldListener extends AbstractAdditionalFieldListener
14
{
15
    protected string $attribute = AdditionalField::class;
16
17 6
    public function finalize(): void
18
    {
19 6
        foreach ($this->methods as $method) {
20 1
            foreach ($this->reader->getFunctionMetadata($method->method, $this->attribute) as $attribute) {
21 1
                $type = $this->typeRegistry->get($attribute->targetType);
22
23 1
                if ($type instanceof DynamicObjectTypeInterface) {
24 1
                    $type->addAdditionalField(new ReflectionMethodWithAttribute($method->method, $attribute));
25
                }
26
            }
27
        }
28
    }
29
}
30