Completed
Pull Request — master (#45)
by Christoffer
02:23
created

ValidationContext::getSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Validation;
4
5
use Digia\GraphQL\Error\GraphQLError;
6
use Digia\GraphQL\Language\AST\Node\DocumentNode;
7
use Digia\GraphQL\Type\Definition\Field;
8
use Digia\GraphQL\Type\Definition\TypeInterface;
9
use Digia\GraphQL\Type\SchemaInterface;
10
use Digia\GraphQL\Util\TypeInfo;
11
12
class ValidationContext
13
{
14
    /**
15
     * @var SchemaInterface
16
     */
17
    protected $schema;
18
19
    /**
20
     * @var DocumentNode
21
     */
22
    protected $documentNode;
23
24
    /**
25
     * @var TypeInfo
26
     */
27
    protected $typeInfo;
28
29
    /**
30
     * @var array|GraphQLError[]
31
     */
32
    protected $errors = [];
33
34
    /**
35
     * ValidationContext constructor.
36
     * @param SchemaInterface $schema
37
     * @param DocumentNode    $documentNode
38
     * @param TypeInfo        $typeInfo
39
     */
40
    public function __construct(SchemaInterface $schema, DocumentNode $documentNode, TypeInfo $typeInfo)
41
    {
42
        $this->schema       = $schema;
43
        $this->documentNode = $documentNode;
44
        $this->typeInfo     = $typeInfo;
45
    }
46
47
    /**
48
     * @param GraphQLError $error
49
     */
50
    public function reportError(GraphQLError $error): void
51
    {
52
        $this->errors[] = $error;
53
    }
54
55
    /**
56
     * @return array|GraphQLError[]
57
     */
58
    public function getErrors(): array
59
    {
60
        return $this->errors;
61
    }
62
63
    /**
64
     * @return TypeInterface|null
65
     */
66
    public function getParentType(): ?TypeInterface
67
    {
68
        return $this->typeInfo->getParentType();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->typeInfo->getParentType() could return the type Digia\GraphQL\Type\Defin...\CompositeTypeInterface which is incompatible with the type-hinted return null|Digia\GraphQL\Type\Definition\TypeInterface. Consider adding an additional type-check to rule them out.
Loading history...
69
    }
70
71
    /**
72
     * @return Field|null
73
     */
74
    public function getFieldDefinition(): ?Field
75
    {
76
        return $this->typeInfo->getFieldDefinition();
77
    }
78
79
    /**
80
     * @return SchemaInterface
81
     */
82
    public function getSchema(): SchemaInterface
83
    {
84
        return $this->schema;
85
    }
86
}
87