Passed
Pull Request — master (#173)
by Christoffer
02:44
created

BuildingInfo   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 97
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypeDefinitionMap() 0 3 1
A getDocument() 0 3 1
A getOperationTypeDefinition() 0 3 1
A getTypeDefinition() 0 3 1
A getDirectiveDefinitions() 0 3 1
A __construct() 0 12 1
A getSchemaDefinition() 0 3 1
1
<?php
2
3
namespace Digia\GraphQL\Schema\Building;
4
5
use Digia\GraphQL\Language\Node\DirectiveDefinitionNode;
6
use Digia\GraphQL\Language\Node\DocumentNode;
7
use Digia\GraphQL\Language\Node\NodeInterface;
8
use Digia\GraphQL\Language\Node\OperationTypeDefinitionNode;
9
use Digia\GraphQL\Language\Node\SchemaDefinitionNode;
10
use Digia\GraphQL\Language\Node\TypeNodeInterface;
11
use Digia\GraphQL\Type\Definition\TypeInterface;
12
13
class BuildingInfo
14
{
15
    /**
16
     * @var DocumentNode
17
     */
18
    protected $document;
19
20
    /**
21
     * @var TypeInterface[]
22
     */
23
    protected $typeDefinitionMap;
24
25
    /**
26
     * @var DirectiveDefinitionNode[]
27
     */
28
    protected $directiveDefinitions;
29
30
    /**
31
     * @var OperationTypeDefinitionNode[]
32
     */
33
    protected $operationTypeDefinitions;
34
35
    /**
36
     * @var SchemaDefinitionNode|null
37
     */
38
    protected $schemaDefinition;
39
40
    /**
41
     * BuildingInfo constructor.
42
     * @param DocumentNode                  $document
43
     * @param TypeInterface[]               $typeDefinitionMap
44
     * @param DirectiveDefinitionNode[]     $directiveDefinitions
45
     * @param OperationTypeDefinitionNode[] $operationTypeDefinitions
46
     * @param SchemaDefinitionNode|null     $schemaDefinition
47
     */
48
    public function __construct(
49
        DocumentNode $document,
50
        array $typeDefinitionMap,
51
        array $directiveDefinitions,
52
        array $operationTypeDefinitions,
53
        ?SchemaDefinitionNode $schemaDefinition = null
54
    ) {
55
        $this->document                 = $document;
56
        $this->typeDefinitionMap        = $typeDefinitionMap;
57
        $this->directiveDefinitions     = $directiveDefinitions;
58
        $this->operationTypeDefinitions = $operationTypeDefinitions;
59
        $this->schemaDefinition         = $schemaDefinition;
60
    }
61
62
    /**
63
     * @param string $typeName
64
     * @return TypeInterface|null
65
     */
66
    public function getTypeDefinition(string $typeName): ?TypeInterface
67
    {
68
        return $this->typeDefinitionMap[$typeName] ?? null;
69
    }
70
71
    /**
72
     * @param string $operation
73
     * @return TypeNodeInterface|null
74
     */
75
    public function getOperationTypeDefinition(string $operation): ?NodeInterface
76
    {
77
        return $this->operationTypeDefinitions[$operation] ?? $this->typeDefinitionMap[\ucfirst($operation)] ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->operationT...st($operation)] ?? null could return the type Digia\GraphQL\Type\Definition\TypeInterface which is incompatible with the type-hinted return null|Digia\GraphQL\Language\Node\NodeInterface. Consider adding an additional type-check to rule them out.
Loading history...
78
    }
79
80
    /**
81
     * @return DocumentNode
82
     */
83
    public function getDocument(): DocumentNode
84
    {
85
        return $this->document;
86
    }
87
88
    /**
89
     * @return SchemaDefinitionNode|null
90
     */
91
    public function getSchemaDefinition(): ?SchemaDefinitionNode
92
    {
93
        return $this->schemaDefinition;
94
    }
95
96
    /**
97
     * @return TypeInterface[]
98
     */
99
    public function getTypeDefinitionMap(): array
100
    {
101
        return $this->typeDefinitionMap;
102
    }
103
104
    /**
105
     * @return DirectiveDefinitionNode[]
106
     */
107
    public function getDirectiveDefinitions(): array
108
    {
109
        return $this->directiveDefinitions;
110
    }
111
}
112