AbstractObjectField   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 62
ccs 20
cts 20
cp 1
rs 10
wmc 12

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getType() 0 3 1
A getMode() 0 4 1
A getDeprecationReason() 0 4 1
A getDescription() 0 4 1
B getArguments() 0 18 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Field;
6
7
use Andi\GraphQL\Argument\Argument;
8
use Andi\GraphQL\Definition\Field\ArgumentInterface;
9
use Andi\GraphQL\Definition\Field\ArgumentsAwareInterface;
10
use Andi\GraphQL\Definition\Field\ObjectFieldInterface;
11
use GraphQL\Type\Definition as Webonyx;
12
13
abstract class AbstractObjectField implements ObjectFieldInterface, ArgumentsAwareInterface
14
{
15
    use FieldExtractorTrait;
16
17
    protected string $name;
18
19
    protected string $description;
20
21
    protected string $type;
22
23
    protected int $mode;
24
25
    protected string $deprecationReason;
26
27
    protected iterable $arguments;
28
29 14
    public function getName(): string
30
    {
31 14
        return $this->name;
32
    }
33
34 14
    public function getDescription(): ?string
35
    {
36
        /** @psalm-suppress RedundantPropertyInitializationCheck */
37 14
        return $this->description ?? null;
38
    }
39
40 14
    public function getDeprecationReason(): ?string
41
    {
42
        /** @psalm-suppress RedundantPropertyInitializationCheck */
43 14
        return $this->deprecationReason ?? null;
44
    }
45
46 14
    public function getType(): string
47
    {
48 14
        return $this->type;
49
    }
50
51 14
    public function getMode(): int
52
    {
53
        /** @psalm-suppress RedundantPropertyInitializationCheck */
54 14
        return $this->mode ?? 0;
55
    }
56
57 14
    public function getArguments(): iterable
58
    {
59
        /**
60
         * @psalm-suppress RedundantPropertyInitializationCheck
61
         * @psalm-suppress RedundantCondition
62
         * @psalm-suppress TypeDoesNotContainType
63
         */
64 14
        foreach ($this->arguments ?? [] as $name => $argument) {
65 1
            if ($argument instanceof ArgumentInterface || $argument instanceof Webonyx\Type) {
66 1
                yield $argument;
67 1
            } elseif (\is_string($argument)) {
68 1
                yield new Argument($name, $argument);
69 1
            } elseif (\is_array($argument)) {
70 1
                if (\is_string($name)) {
71 1
                    $argument['name'] ??= $name;
72
                }
73
74 1
                yield $this->extract($argument, Argument::class);
75
            }
76
        }
77
    }
78
}
79