Passed
Pull Request — master (#233)
by Christoffer
03:30
created

ListValueNode::toAST()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
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 ListValueNode extends AbstractNode implements ValueNodeInterface
8
{
9
    /**
10
     * @var ValueNodeInterface[]
11
     */
12
    protected $values;
13
14
    /**
15
     * ListValueNode constructor.
16
     *
17
     * @param ValueNodeInterface[] $values
18
     * @param Location|null        $location
19
     */
20
    public function __construct(array $values, ?Location $location)
21
    {
22
        parent::__construct(NodeKindEnum::LIST, $location);
23
24
        $this->values = $values;
25
    }
26
27
    /**
28
     * @return array|ValueNodeInterface[]
29
     */
30
    public function getValues(): array
31
    {
32
        return $this->values;
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function getValuesAST(): array
39
    {
40
        return \array_map(function (ValueNodeInterface $node) {
41
            return $node->toAST();
42
        }, $this->values);
43
    }
44
45
    /**
46
     * @param array|ValueNodeInterface[] $values
47
     * @return $this
48
     */
49
    public function setValues(array $values)
50
    {
51
        $this->values = $values;
52
        return $this;
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function toAST(): array
59
    {
60
        return [
61
            'kind'   => $this->kind,
62
            'loc'    => $this->getLocationAST(),
63
            'values' => $this->getValuesAST(),
64
        ];
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    public function __toString(): string
71
    {
72
        return \json_encode(\array_map(function (ValueAwareInterface $node) {
73
            return $node->getValue();
74
        }, $this->getValues()));
75
    }
76
}
77