Passed
Push — master ( da4ce9...54c779 )
by Christoffer
02:24
created

SchemaExtensionNode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toAST() 0 7 1
A getOperationTypes() 0 3 1
A __construct() 0 6 1
A getOperationTypesAST() 0 5 1
A setOperationTypes() 0 4 1
1
<?php
2
3
namespace Digia\GraphQL\Language\Node;
4
5
use Digia\GraphQL\Language\Location;
6
7
class SchemaExtensionNode extends AbstractNode implements TypeSystemExtensionNodeInterface, DirectivesAwareInterface
8
{
9
    use DirectivesTrait;
10
11
    /**
12
     * @var OperationTypeDefinitionNode[]
13
     */
14
    protected $operationTypes;
15
16
    /**
17
     * SchemaExtensionNode constructor.
18
     * @param DirectiveNode[]               $directives
19
     * @param OperationTypeDefinitionNode[] $operationTypes
20
     * @param Location|null                 $location
21
     */
22
    public function __construct(array $directives, array $operationTypes, ?Location $location)
23
    {
24
        parent::__construct(NodeKindEnum::SCHEMA_EXTENSION, $location);
25
26
        $this->directives     = $directives;
27
        $this->operationTypes = $operationTypes;
28
    }
29
30
    /**
31
     * @return OperationTypeDefinitionNode[]
32
     */
33
    public function getOperationTypes(): array
34
    {
35
        return $this->operationTypes;
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function getOperationTypesAST(): array
42
    {
43
        return \array_map(function (OperationTypeDefinitionNode $node) {
44
            return $node->toAST();
45
        }, $this->operationTypes);
46
    }
47
48
    /**
49
     * @param OperationTypeDefinitionNode[] $operationTypes
50
     * @return $this
51
     */
52
    public function setOperationTypes(array $operationTypes)
53
    {
54
        $this->operationTypes = $operationTypes;
55
        return $this;
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function toAST(): array
62
    {
63
        return [
64
            'kind'           => $this->kind,
65
            'directives'     => $this->getDirectivesAST(),
66
            'operationTypes' => $this->getOperationTypesAST(),
67
            'loc'            => $this->getLocationAST(),
68
        ];
69
    }
70
}
71