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

ResolveInfo::getVariableValues()   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\Execution;
4
5
use Digia\GraphQL\Language\Node\FieldNode;
6
use Digia\GraphQL\Language\Node\OperationDefinitionNode;
7
use Digia\GraphQL\Type\Definition\ObjectType;
8
use Digia\GraphQL\Type\Definition\OutputTypeInterface;
9
use Digia\GraphQL\Type\Definition\TypeInterface;
10
use Digia\GraphQL\Type\SchemaInterface;
11
12
class ResolveInfo
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $fieldName;
18
19
    /**
20
     * @var FieldNode[]
21
     */
22
    protected $fieldNodes;
23
24
    /**
25
     * @var OutputTypeInterface
26
     */
27
    protected $returnType;
28
29
    /**
30
     * @var ObjectType
31
     */
32
    protected $parentType;
33
34
    /**
35
     * @var ResponsePath
0 ignored issues
show
Bug introduced by
The type Digia\GraphQL\Execution\ResponsePath was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
     */
37
    protected $path;
38
39
    /**
40
     * @var SchemaInterface
41
     */
42
    protected $schema;
43
44
    /**
45
     * @var array
46
     */
47
    protected $fragments;
48
49
    /**
50
     * @var mixed
51
     */
52
    protected $rootValue;
53
54
    /**
55
     * @var OperationDefinitionNode
56
     */
57
    protected $operation;
58
59
    /**
60
     * @var array
61
     */
62
    protected $variableValues;
63
64
    /**
65
     * ResolveInfo constructor.
66
     * @param string                  $fieldName
67
     * @param FieldNode[]             $fieldNodes
68
     * @param TypeInterface           $returnType
69
     * @param ObjectType              $parentType
70
     * @param array|null              $path
71
     * @param SchemaInterface         $schema
72
     * @param array                   $fragments
73
     * @param mixed                   $rootValue
74
     * @param OperationDefinitionNode $operation
75
     * @param array                   $variableValues
76
     */
77
    public function __construct(
78
        string $fieldName,
79
        ?array $fieldNodes,
80
        TypeInterface $returnType,
81
        ObjectType $parentType,
82
        ?array $path,
83
        SchemaInterface $schema,
84
        array $fragments,
85
        $rootValue,
86
        OperationDefinitionNode $operation,
87
        array $variableValues
88
    ) {
89
        $this->fieldName      = $fieldName;
90
        $this->fieldNodes     = $fieldNodes;
91
        $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...
92
        $this->parentType     = $parentType;
93
        $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...
94
        $this->schema         = $schema;
95
        $this->fragments      = $fragments;
96
        $this->rootValue      = $rootValue;
97
        $this->operation      = $operation;
98
        $this->variableValues = $variableValues;
99
    }
100
101
102
    /**
103
     * @return string
104
     */
105
    public function getFieldName(): string
106
    {
107
        return $this->fieldName;
108
    }
109
110
    /**
111
     * @return FieldNode[]
112
     */
113
    public function getFieldNodes(): array
114
    {
115
        return $this->fieldNodes;
116
    }
117
118
    /**
119
     * @return OutputTypeInterface
120
     */
121
    public function getReturnType(): OutputTypeInterface
122
    {
123
        return $this->returnType;
124
    }
125
126
    /**
127
     * @return ObjectType
128
     */
129
    public function getParentType(): ObjectType
130
    {
131
        return $this->parentType;
132
    }
133
134
    /**
135
     * @return array
136
     */
137
    public function getPath(): ?array
138
    {
139
        return $this->path;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->path returns the type Digia\GraphQL\Execution\ResponsePath which is incompatible with the type-hinted return null|array.
Loading history...
140
    }
141
142
    /**
143
     * @return SchemaInterface
144
     */
145
    public function getSchema(): SchemaInterface
146
    {
147
        return $this->schema;
148
    }
149
150
    /**
151
     * @return array
152
     */
153
    public function getFragments(): array
154
    {
155
        return $this->fragments;
156
    }
157
158
    /**
159
     * @return mixed
160
     */
161
    public function getRootValue()
162
    {
163
        return $this->rootValue;
164
    }
165
166
    /**
167
     * @return OperationDefinitionNode
168
     */
169
    public function getOperation(): OperationDefinitionNode
170
    {
171
        return $this->operation;
172
    }
173
174
    /**
175
     * @return array
176
     */
177
    public function getVariableValues(): array
178
    {
179
        return $this->variableValues;
180
    }
181
}
182