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

AbstractObjectField::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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