Passed
Push — master ( 22d357...2883c4 )
by Christoffer
02:52
created

VariableDefinitionNode::toAST()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Language\Node;
4
5
use Digia\GraphQL\Language\Location;
6
7
class VariableDefinitionNode extends AbstractNode implements DefinitionNodeInterface
8
{
9
    use DefaultValueTrait;
10
    use TypeTrait;
11
12
    /**
13
     * @var VariableNode
14
     */
15
    protected $variable;
16
17
    /**
18
     * VariableDefinitionNode constructor.
19
     *
20
     * @param VariableNode            $variable
21
     * @param TypeNodeInterface       $type
22
     * @param ValueNodeInterface|null $defaultValue
23
     * @param Location|null           $location
24
     */
25
    public function __construct(
26
        VariableNode $variable,
27
        TypeNodeInterface $type,
28
        ?ValueNodeInterface $defaultValue,
29
        ?Location $location
30
    ) {
31
        parent::__construct(NodeKindEnum::VARIABLE_DEFINITION, $location);
32
33
        $this->variable     = $variable;
34
        $this->type         = $type;
35
        $this->defaultValue = $defaultValue;
36
    }
37
38
    /**
39
     * @return VariableNode
40
     */
41
    public function getVariable(): VariableNode
42
    {
43
        return $this->variable;
44
    }
45
46
    /**
47
     * @return array
48
     */
49
    public function getVariableAST(): array
50
    {
51
        return $this->variable->toAST();
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57
    public function __toString(): string
58
    {
59
        return (string)$this->type;
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65
    public function toAST(): array
66
    {
67
        return [
68
            'kind'     => $this->kind,
69
            'variable' => $this->getVariableAST(),
70
            'type'     => $this->getTypeAST(),
71
            'loc'      => $this->getLocationAST(),
72
        ];
73
    }
74
}
75