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

OperationDefinitionNode::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Digia\GraphQL\Language\Node;
4
5
use Digia\GraphQL\Language\Location;
6
7
class OperationDefinitionNode extends AbstractNode implements ExecutableDefinitionNodeInterface,
8
    DirectivesAwareInterface, NameAwareInterface
9
{
10
    use NameTrait;
11
    use DirectivesTrait;
12
    use VariableDefinitionsTrait;
13
    use SelectionSetTrait;
14
15
    /**
16
     * @var string
17
     */
18
    protected $operation;
19
20
    /**
21
     * OperationDefinitionNode constructor.
22
     *
23
     * @param string                   $operation
24
     * @param NameNode|null            $name
25
     * @param VariableDefinitionNode[] $variableDefinitions
26
     * @param DirectiveNode[]          $directives
27
     * @param SelectionSetNode|null    $selectionSet
28
     * @param Location|null            $location
29
     */
30
    public function __construct(
31
        string $operation,
32
        ?NameNode $name,
33
        array $variableDefinitions,
34
        array $directives,
35
        ?SelectionSetNode $selectionSet,
36
        ?Location $location
37
    ) {
38
        parent::__construct(NodeKindEnum::OPERATION_DEFINITION, $location);
39
40
        $this->operation           = $operation;
41
        $this->name                = $name;
42
        $this->variableDefinitions = $variableDefinitions;
43
        $this->directives          = $directives;
44
        $this->selectionSet        = $selectionSet;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getOperation(): string
51
    {
52
        return $this->operation;
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function toAST(): array
59
    {
60
        return [
61
            'kind'                => $this->kind,
62
            'loc'                 => $this->getLocationAST(),
63
            'operation'           => $this->operation,
64
            'name'                => $this->getNameAST(),
65
            'variableDefinitions' => $this->getVariableDefinitionsAST(),
66
            'directives'          => $this->getDirectivesAST(),
67
            'selectionSet'        => $this->getSelectionSetAST(),
68
        ];
69
    }
70
}
71