Passed
Pull Request — master (#23)
by Christoffer
02:07 queued 19s
created

SelectionSetNode::setSelections()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Language\AST\Node;
4
5
use Digia\GraphQL\Language\AST\NodeKindEnum;
6
use Digia\GraphQL\Util\SerializationInterface;
7
8
class SelectionSetNode extends AbstractNode implements NodeInterface
9
{
10
11
    /**
12
     * @var string
13
     */
14
    protected $kind = NodeKindEnum::SELECTION_SET;
15
16
    /**
17
     * @var SelectionNodeInterface[]
18
     */
19
    protected $selections;
20
21
    /**
22
     * @return SelectionNodeInterface[]
23
     */
24
    public function getSelections(): array
25
    {
26
        return $this->selections;
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public function getSelectionsAsArray(): array
33
    {
34
        return array_map(function (SerializationInterface $node) {
35
            return $node->toArray();
36
        }, $this->selections);
37
    }
38
39
    /**
40
     * @param SelectionNodeInterface[] $selections
41
     * @return SelectionSetNode
42
     */
43
    public function setSelections(array $selections): SelectionSetNode
44
    {
45
        $this->selections = $selections;
46
        return $this;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function toArray(): array
53
    {
54
        return [
55
            'kind'       => $this->kind,
56
            'loc'        => $this->getLocationAsArray(),
57
            'selections' => $this->getSelectionsAsArray(),
58
        ];
59
    }
60
}
61