AdditionalFieldListener::finalize()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 5
c 1
b 0
f 1
nc 4
nop 0
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 4
rs 10
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