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

ObjectValueNode::getFieldsAsArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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