Passed
Pull Request — master (#143)
by Christoffer
02:23
created

ResolveInfo   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 168
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 168
rs 10
c 0
b 0
f 0
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 22 1
A getVariableValues() 0 3 1
A getFragments() 0 3 1
A getReturnType() 0 3 1
A getFieldName() 0 3 1
A getPath() 0 3 1
A getOperation() 0 3 1
A getSchema() 0 3 1
A getRootValue() 0 3 1
A getParentType() 0 3 1
A getFieldNodes() 0 3 1
1
<?php
2
3
namespace Digia\GraphQL\Execution\Resolver;
4
5
use Digia\GraphQL\Execution\ResponsePath;
6
use Digia\GraphQL\Language\Node\FieldNode;
7
use Digia\GraphQL\Language\Node\OperationDefinitionNode;
8
use Digia\GraphQL\Type\Definition\ObjectType;
9
use Digia\GraphQL\Type\Definition\OutputTypeInterface;
10
use Digia\GraphQL\Type\Definition\TypeInterface;
11
use Digia\GraphQL\Type\SchemaInterface;
12
13
class ResolveInfo
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $fieldName;
19
20
    /**
21
     * @var FieldNode[]
22
     */
23
    protected $fieldNodes;
24
25
    /**
26
     * @var OutputTypeInterface
27
     */
28
    protected $returnType;
29
30
    /**
31
     * @var ObjectType
32
     */
33
    protected $parentType;
34
35
    /**
36
     * @var ResponsePath
37
     */
38
    protected $path;
39
40
    /**
41
     * @var SchemaInterface
42
     */
43
    protected $schema;
44
45
    /**
46
     * @var array
47
     */
48
    protected $fragments;
49
50
    /**
51
     * @var mixed
52
     */
53
    protected $rootValue;
54
55
    /**
56
     * @var OperationDefinitionNode
57
     */
58
    protected $operation;
59
60
    /**
61
     * @var array
62
     */
63
    protected $variableValues;
64
65
    /**
66
     * ResolveInfo constructor.
67
     * @param string                  $fieldName
68
     * @param FieldNode[]             $fieldNodes
69
     * @param TypeInterface           $returnType
70
     * @param ObjectType              $parentType
71
     * @param array|null              $path
72
     * @param SchemaInterface         $schema
73
     * @param array                   $fragments
74
     * @param mixed                   $rootValue
75
     * @param OperationDefinitionNode $operation
76
     * @param array                   $variableValues
77
     */
78
    public function __construct(
79
        string $fieldName,
80
        ?array $fieldNodes,
81
        TypeInterface $returnType,
82
        ObjectType $parentType,
83
        ?array $path,
84
        SchemaInterface $schema,
85
        array $fragments,
86
        $rootValue,
87
        OperationDefinitionNode $operation,
88
        array $variableValues
89
    ) {
90
        $this->fieldName      = $fieldName;
91
        $this->fieldNodes     = $fieldNodes;
92
        $this->returnType     = $returnType;
0 ignored issues
show
Documentation Bug introduced by
It seems like $returnType of type Digia\GraphQL\Type\Definition\TypeInterface is incompatible with the declared type Digia\GraphQL\Type\Definition\OutputTypeInterface of property $returnType.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
93
        $this->parentType     = $parentType;
94
        $this->path           = $path;
0 ignored issues
show
Documentation Bug introduced by
It seems like $path can also be of type array. However, the property $path is declared as type Digia\GraphQL\Execution\ResponsePath. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
95
        $this->schema         = $schema;
96
        $this->fragments      = $fragments;
97
        $this->rootValue      = $rootValue;
98
        $this->operation      = $operation;
99
        $this->variableValues = $variableValues;
100
    }
101
102
103
    /**
104
     * @return string
105
     */
106
    public function getFieldName(): string
107
    {
108
        return $this->fieldName;
109
    }
110
111
    /**
112
     * @return FieldNode[]
113
     */
114
    public function getFieldNodes(): array
115
    {
116
        return $this->fieldNodes;
117
    }
118
119
    /**
120
     * @return OutputTypeInterface
121
     */
122
    public function getReturnType(): OutputTypeInterface
123
    {
124
        return $this->returnType;
125
    }
126
127
    /**
128
     * @return ObjectType
129
     */
130
    public function getParentType(): ObjectType
131
    {
132
        return $this->parentType;
133
    }
134
135
    /**
136
     * @return ResponsePath
137
     */
138
    public function getPath(): ResponsePath
139
    {
140
        return $this->path;
141
    }
142
143
    /**
144
     * @return SchemaInterface
145
     */
146
    public function getSchema(): SchemaInterface
147
    {
148
        return $this->schema;
149
    }
150
151
    /**
152
     * @return array
153
     */
154
    public function getFragments(): array
155
    {
156
        return $this->fragments;
157
    }
158
159
    /**
160
     * @return mixed
161
     */
162
    public function getRootValue()
163
    {
164
        return $this->rootValue;
165
    }
166
167
    /**
168
     * @return OperationDefinitionNode
169
     */
170
    public function getOperation(): OperationDefinitionNode
171
    {
172
        return $this->operation;
173
    }
174
175
    /**
176
     * @return array
177
     */
178
    public function getVariableValues(): array
179
    {
180
        return $this->variableValues;
181
    }
182
}
183