AttributedMutationFieldListener::finalize()   A
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.0488

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 7
c 1
b 0
f 1
nc 12
nop 0
dl 0
loc 11
ccs 7
cts 8
cp 0.875
crap 5.0488
rs 9.6111
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Spiral\Listener;
6
7
use Andi\GraphQL\Attribute\MutationField;
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(MutationField::class)]
15
final class AttributedMutationFieldListener extends AbstractAdditionalFieldListener
16
{
17
    protected string $attribute = MutationField::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
        $type = $this->config->getMutationType();
30
31 2
        $mutation = null !== $type && $this->typeRegistry->has($type)
32 2
            ? $this->typeRegistry->get($type)
33
            : null;
34
35 2
        if ($mutation instanceof DynamicObjectTypeInterface) {
36 2
            foreach ($this->methods as $method) {
37 1
                $mutation->addAdditionalField($method);
38
            }
39
        }
40
    }
41
}
42