Passed
Pull Request — master (#23)
by Christoffer
02:07 queued 19s
created

DirectiveDefinitionNode   A

Complexity

Total Complexity 4

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 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLocations() 0 3 1
A getLocationsAsArray() 0 5 1
A toArray() 0 9 1
A setLocations() 0 4 1
1
<?php
2
3
namespace Digia\GraphQL\Language\AST\Node;
4
5
use Digia\GraphQL\Language\AST\NodeKindEnum;
6
use Digia\GraphQL\Util\SerializationInterface;
7
8
class DirectiveDefinitionNode extends AbstractNode implements DefinitionNodeInterface
9
{
10
11
    use DescriptionTrait;
12
    use NameTrait;
13
    use InputArgumentsTrait;
14
15
    /**
16
     * @var string
17
     */
18
    protected $kind = NodeKindEnum::DIRECTIVE_DEFINITION;
19
20
    /**
21
     * @var NameNode[]
22
     */
23
    protected $locations;
24
25
    /**
26
     * @return NameNode[]
27
     */
28
    public function getLocations(): array
29
    {
30
        return $this->locations;
31
    }
32
33
    /**
34
     * @return array
35
     */
36
    public function getLocationsAsArray(): array
37
    {
38
        return array_map(function (SerializationInterface $node) {
39
            return $node->toArray();
40
        }, $this->locations);
41
    }
42
43
    /**
44
     * @param array|NameNode[] $locations
45
     * @return $this
46
     */
47
    public function setLocations(array $locations)
48
    {
49
        $this->locations = $locations;
50
        return $this;
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function toArray(): array
57
    {
58
        return [
59
            'kind'        => $this->kind,
60
            'description' => $this->getDescriptionAsArray(),
61
            'name'        => $this->getNameAsArray(),
62
            'arguments'   => $this->getArgumentsAsArray(),
63
            'locations'   => $this->getLocationsAsArray(),
64
            'loc'         => $this->getLocationAsArray(),
65
        ];
66
    }
67
}
68