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

DocumentNode::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Digia\GraphQL\Language\Node;
4
5
use Digia\GraphQL\Language\Location;
6
7
class DocumentNode extends AbstractNode
8
{
9
    /**
10
     * @var DefinitionNodeInterface[]|TypeExtensionNodeInterface[]
11
     */
12
    protected $definitions;
13
14
    /**
15
     * DocumentNode constructor.
16
     *
17
     * @param DefinitionNodeInterface[] $definitions
18
     * @param Location|null             $location
19
     */
20
    public function __construct(array $definitions, ?Location $location)
21
    {
22
        parent::__construct(NodeKindEnum::DOCUMENT, $location);
23
24
        $this->definitions = $definitions;
25
    }
26
27
    /**
28
     * @return DefinitionNodeInterface[]|TypeExtensionNodeInterface[]
29
     */
30
    public function getDefinitions(): array
31
    {
32
        return $this->definitions;
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function getDefinitionsAST(): array
39
    {
40
        return \array_map(function (NodeInterface $node) {
41
            return $node->toAST();
42
        }, $this->definitions);
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function toAST(): array
49
    {
50
        return [
51
            'kind'        => $this->kind,
52
            'definitions' => $this->getDefinitionsAST(),
53
            'loc'         => $this->getLocationAST(),
54
        ];
55
    }
56
57
    /**
58
     * @param DefinitionNodeInterface[] $definitions
59
     * @return DocumentNode
60
     */
61
    protected function setDefinitions(array $definitions): DocumentNode
62
    {
63
        $this->definitions = $definitions;
64
        return $this;
65
    }
66
}
67