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

ValidationContext::getFieldDefinition()   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\ValidationException;
6
use Digia\GraphQL\Language\AST\Node\DocumentNode;
7
use Digia\GraphQL\Type\Definition\Argument;
8
use Digia\GraphQL\Type\Definition\Directive;
9
use Digia\GraphQL\Type\Definition\Field;
10
use Digia\GraphQL\Type\Definition\TypeInterface;
11
use Digia\GraphQL\Type\SchemaInterface;
12
use Digia\GraphQL\Util\TypeInfo;
13
14
class ValidationContext
15
{
16
    /**
17
     * @var SchemaInterface
18
     */
19
    protected $schema;
20
21
    /**
22
     * @var DocumentNode
23
     */
24
    protected $documentNode;
25
26
    /**
27
     * @var TypeInfo
28
     */
29
    protected $typeInfo;
30
31
    /**
32
     * @var array|ValidationException[]
33
     */
34
    protected $errors = [];
35
36
    /**
37
     * ValidationContext constructor.
38
     * @param SchemaInterface $schema
39
     * @param DocumentNode    $documentNode
40
     * @param TypeInfo        $typeInfo
41
     */
42
    public function __construct(SchemaInterface $schema, DocumentNode $documentNode, TypeInfo $typeInfo)
43
    {
44
        $this->schema       = $schema;
45
        $this->documentNode = $documentNode;
46
        $this->typeInfo     = $typeInfo;
47
    }
48
49
    /**
50
     * @param ValidationException $error
51
     */
52
    public function reportError(ValidationException $error): void
53
    {
54
        $this->errors[] = $error;
55
    }
56
57
    /**
58
     * @return array|ValidationException[]
59
     */
60
    public function getErrors(): array
61
    {
62
        return $this->errors;
63
    }
64
65
    /**
66
     * @return TypeInterface|null
67
     */
68
    public function getParentType(): ?TypeInterface
69
    {
70
        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...
71
    }
72
73
    /**
74
     * @return Field|null
75
     */
76
    public function getFieldDefinition(): ?Field
77
    {
78
        return $this->typeInfo->getFieldDefinition();
79
    }
80
81
    /**
82
     * @return SchemaInterface
83
     */
84
    public function getSchema(): SchemaInterface
85
    {
86
        return $this->schema;
87
    }
88
89
    /**
90
     * @return Argument|null
91
     */
92
    public function getArgument(): ?Argument
93
    {
94
        return $this->typeInfo->getArgument();
95
    }
96
97
    /**
98
     * @return Directive|null
99
     */
100
    public function getDirective(): ?Directive
101
    {
102
        return $this->typeInfo->getDirective();
103
    }
104
}
105