Completed
Push — master ( 7faae5...9f7b4d )
by Christoffer
02:27
created

DirectiveDefinitionNode::getLocationsAsArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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