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

SelectionSetNode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSelections() 0 3 1
A setSelections() 0 4 1
A getSelectionsAST() 0 5 1
A toAST() 0 6 1
1
<?php
2
3
namespace Digia\GraphQL\Language\Node;
4
5
use Digia\GraphQL\Language\Location;
6
7
class SelectionSetNode extends AbstractNode
8
{
9
    /**
10
     * @var SelectionNodeInterface[]
11
     */
12
    protected $selections = [];
13
14
    /**
15
     * SelectionSetNode constructor.
16
     *
17
     * @param SelectionNodeInterface[] $selections
18
     * @param Location|null            $location
19
     */
20
    public function __construct(array $selections, ?Location $location)
21
    {
22
        parent::__construct(NodeKindEnum::SELECTION_SET, $location);
23
24
        $this->selections = $selections;
25
    }
26
27
    /**
28
     * @return SelectionNodeInterface[]
29
     */
30
    public function getSelections(): array
31
    {
32
        return $this->selections;
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function getSelectionsAST(): array
39
    {
40
        return \array_map(function (SelectionNodeInterface $node) {
41
            return $node->toAST();
42
        }, $this->selections);
43
    }
44
45
    /**
46
     * @param SelectionNodeInterface[] $selections
47
     * @return SelectionSetNode
48
     */
49
    public function setSelections(array $selections): SelectionSetNode
50
    {
51
        $this->selections = $selections;
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
            'selections' => $this->getSelectionsAST(),
64
        ];
65
    }
66
}
67