Passed
Push — master ( 383648...c60c96 )
by Andrey
50s queued 13s
created

AbstractObjectField::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

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