Passed
Push — master ( 898411...5b804b )
by Andrey
56s queued 13s
created

AbstractObjectField   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 54
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 54
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 3 1
A getDeprecationReason() 0 3 1
A getDescription() 0 3 1
B getArguments() 0 13 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 14
        return $this->description ?? null;
37
    }
38
39 14
    public function getDeprecationReason(): ?string
40
    {
41 14
        return $this->deprecationReason ?? null;
42
    }
43
44 14
    public function getType(): string
45
    {
46 14
        return $this->type;
47
    }
48
49 14
    public function getMode(): int
50
    {
51 14
        return $this->mode ?? 0;
52
    }
53
54 14
    public function getArguments(): iterable
55
    {
56 14
        foreach ($this->arguments ?? [] as $name => $argument) {
57 1
            if ($argument instanceof ArgumentInterface || $argument instanceof Webonyx\Type) {
58 1
                yield $argument;
59 1
            } elseif (is_string($argument)) {
60 1
                yield new Argument($name, $argument);
61 1
            } elseif (is_array($argument)) {
62 1
                if (is_string($name)) {
63 1
                    $argument['name'] ??= $name;
64
                }
65
66 1
                yield $this->extract($argument, Argument::class);
67
            }
68
        }
69
    }
70
}
71