Passed
Pull Request — master (#196)
by Christoffer
02:50
created

DirectiveDefinitionNode::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 5
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Language\Node;
4
5
use Digia\GraphQL\Language\Location;
6
use Digia\GraphQL\Util\SerializationInterface;
7
8
class DirectiveDefinitionNode extends AbstractNode implements DefinitionNodeInterface, NameAwareInterface
9
{
10
    use DescriptionTrait;
11
    use NameTrait;
12
    use InputArgumentsTrait;
13
14
    /**
15
     * @var NameNode[]
16
     */
17
    protected $locations;
18
19
    /**
20
     * DirectiveDefinitionNode constructor.
21
     *
22
     * @param StringValueNode|null $description
23
     * @param NameNode             $name
24
     * @param ArgumentNode[]       $arguments
25
     * @param NameNode[]           $locations
26
     * @param Location|null        $location
27
     */
28
    public function __construct(
29
        ?StringValueNode $description,
30
        NameNode $name,
31
        array $arguments,
32
        array $locations,
33
        ?Location $location
34
    ) {
35
        parent::__construct(NodeKindEnum::DIRECTIVE_DEFINITION, $location);
36
37
        $this->description = $description;
38
        $this->name        = $name;
39
        $this->arguments   = $arguments;
0 ignored issues
show
Documentation Bug introduced by
It seems like $arguments of type Digia\GraphQL\Language\Node\ArgumentNode[] is incompatible with the declared type Digia\GraphQL\Language\N...utValueDefinitionNode[] of property $arguments.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
        $this->locations   = $locations;
41
    }
42
43
    /**
44
     * @return NameNode[]
45
     */
46
    public function getLocations(): array
47
    {
48
        return $this->locations;
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function getLocationsAsArray(): array
55
    {
56
        return \array_map(function (SerializationInterface $node) {
57
            return $node->toArray();
58
        }, $this->locations);
59
    }
60
61
    /**
62
     * @param NameNode[] $locations
63
     * @return $this
64
     */
65
    public function setLocations(array $locations)
66
    {
67
        $this->locations = $locations;
68
        return $this;
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function toArray(): array
75
    {
76
        return [
77
            'kind'        => $this->kind,
78
            'description' => $this->getDescriptionAsArray(),
79
            'name'        => $this->getNameAsArray(),
80
            'arguments'   => $this->getArgumentsAsArray(),
81
            'locations'   => $this->getLocationsAsArray(),
82
            'loc'         => $this->getLocationAsArray(),
83
        ];
84
    }
85
}
86