Completed
Pull Request — master (#70)
by Christoffer
02:06
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\Node\NodeKindEnum;
6
use Digia\GraphQL\Util\SerializationInterface;
7
8
class DocumentNode extends AbstractNode implements NodeInterface
9
{
10
11
    /**
12
     * @var string
13
     */
14
    protected $kind = NodeKindEnum::DOCUMENT;
15
16
    /**
17
     * @var array|DefinitionNodeInterface[]
18
     */
19
    protected $definitions;
20
21
    /**
22
     * @return array|DefinitionNodeInterface[]
23
     */
24
    public function getDefinitions(): array
25
    {
26
        return $this->definitions;
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public function getDefinitionsAsArray(): array
33
    {
34
        return array_map(function (SerializationInterface $node) {
35
            return $node->toArray();
36
        }, $this->definitions);
37
    }
38
39
    /**
40
     * @param array|DefinitionNodeInterface[] $definitions
41
     * @return DocumentNode
42
     */
43
    public function setDefinitions($definitions)
44
    {
45
        $this->definitions = $definitions;
46
        return $this;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function toArray(): array
53
    {
54
        return [
55
            'kind'        => $this->kind,
56
            'definitions' => $this->getDefinitionsAsArray(),
57
            'loc'         => $this->getLocationAsArray(),
58
        ];
59
    }
60
}
61