Skip to content

Commit cbdf330

Browse files
authored
Ensure properties annotated to hold NodeList are not null (#770)
1 parent b54aa7f commit cbdf330

29 files changed

+257
-213
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Fix:
1616
Feat:
1717
- Open ReferenceExecutor for extending
1818

19+
Fix:
20+
- Ensure properties annotated to hold NodeList are not null
21+
- Validate that directive argument names do not use reserved or duplicate names
22+
1923
#### 14.5.1
2024

2125
Fix:

phpstan-baseline.neon

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,6 @@ parameters:
155155
count: 1
156156
path: src/Type/SchemaValidationContext.php
157157

158-
-
159-
message: "#^Only booleans are allowed in &&, array\\<GraphQL\\\\Language\\\\AST\\\\Node\\>\\|GraphQL\\\\Language\\\\AST\\\\Node\\|GraphQL\\\\Language\\\\AST\\\\TypeDefinitionNode\\|GraphQL\\\\Language\\\\AST\\\\TypeNode\\|null given on the left side\\.$#"
160-
count: 1
161-
path: src/Type/SchemaValidationContext.php
162-
163158
-
164159
message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\OperationTypeDefinitionNode\\|null given\\.$#"
165160
count: 1
@@ -171,13 +166,8 @@ parameters:
171166
path: src/Type/SchemaValidationContext.php
172167

173168
-
174-
message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Error\\\\Error\\|null given\\.$#"
175-
count: 1
176-
path: src/Type/SchemaValidationContext.php
177-
178-
-
179-
message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\InputValueDefinitionNode given\\.$#"
180-
count: 1
169+
message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\InputValueDefinitionNode\\|null given\\.$#"
170+
count: 2
181171
path: src/Type/SchemaValidationContext.php
182172

183173
-
@@ -190,26 +180,6 @@ parameters:
190180
count: 1
191181
path: src/Type/SchemaValidationContext.php
192182

193-
-
194-
message: "#^Only booleans are allowed in &&, array\\<GraphQL\\\\Language\\\\AST\\\\FieldDefinitionNode\\> given on the left side\\.$#"
195-
count: 1
196-
path: src/Type/SchemaValidationContext.php
197-
198-
-
199-
message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\DirectiveDefinitionNode\\|GraphQL\\\\Language\\\\AST\\\\EnumTypeDefinitionNode\\|GraphQL\\\\Language\\\\AST\\\\InputObjectTypeDefinitionNode\\|GraphQL\\\\Language\\\\AST\\\\InterfaceTypeDefinitionNode\\|GraphQL\\\\Language\\\\AST\\\\ObjectTypeDefinitionNode\\|GraphQL\\\\Language\\\\AST\\\\SchemaDefinitionNode\\|GraphQL\\\\Language\\\\AST\\\\UnionTypeDefinitionNode\\|null given\\.$#"
200-
count: 1
201-
path: src/Type/SchemaValidationContext.php
202-
203-
-
204-
message: "#^Only booleans are allowed in a ternary operator condition, array\\<GraphQL\\\\Language\\\\AST\\\\EnumTypeExtensionNode\\|GraphQL\\\\Language\\\\AST\\\\InputObjectTypeExtensionNode\\|GraphQL\\\\Language\\\\AST\\\\InterfaceTypeExtensionNode\\|GraphQL\\\\Language\\\\AST\\\\ObjectTypeExtensionNode\\|GraphQL\\\\Language\\\\AST\\\\SchemaTypeExtensionNode\\|GraphQL\\\\Language\\\\AST\\\\UnionTypeExtensionNode\\> given\\.$#"
205-
count: 1
206-
path: src/Type/SchemaValidationContext.php
207-
208-
-
209-
message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Language\\\\AST\\\\InterfaceTypeDefinitionNode\\|GraphQL\\\\Language\\\\AST\\\\InterfaceTypeExtensionNode\\|GraphQL\\\\Language\\\\AST\\\\ObjectTypeDefinitionNode\\|GraphQL\\\\Language\\\\AST\\\\ObjectTypeExtensionNode given\\.$#"
210-
count: 1
211-
path: src/Type/SchemaValidationContext.php
212-
213183
-
214184
message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\FieldDefinitionNode\\|null given\\.$#"
215185
count: 1
@@ -225,11 +195,6 @@ parameters:
225195
count: 1
226196
path: src/Type/SchemaValidationContext.php
227197

228-
-
229-
message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\InputValueDefinitionNode\\|null given\\.$#"
230-
count: 2
231-
path: src/Type/SchemaValidationContext.php
232-
233198
-
234199
message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\FieldDefinition\\|null given\\.$#"
235200
count: 1
@@ -255,11 +220,6 @@ parameters:
255220
count: 1
256221
path: src/Type/SchemaValidationContext.php
257222

258-
-
259-
message: "#^Only booleans are allowed in &&, array\\<GraphQL\\\\Language\\\\AST\\\\EnumValueDefinitionNode\\> given on the left side\\.$#"
260-
count: 1
261-
path: src/Type/SchemaValidationContext.php
262-
263223
-
264224
message: "#^Only booleans are allowed in a negated boolean, array\\<GraphQL\\\\Type\\\\Definition\\\\InputObjectField\\> given\\.$#"
265225
count: 1

src/Language/AST/InterfaceTypeExtensionNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class InterfaceTypeExtensionNode extends Node implements TypeExtensionNode
1515
/** @var NodeList<DirectiveNode> */
1616
public $directives;
1717

18-
/** @var NodeList<InterfaceTypeDefinitionNode> */
18+
/** @var NodeList<NamedTypeNode> */
1919
public $interfaces;
2020

2121
/** @var NodeList<FieldDefinitionNode> */

src/Language/Printer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ function (InterfaceTypeDefinitionNode $def): string {
325325
'union',
326326
$def->name,
327327
$this->join($def->directives, ' '),
328-
count($def->types ?? []) > 0
328+
count($def->types) > 0
329329
? '= ' . $this->join($def->types, ' | ')
330330
: '',
331331
],
@@ -417,7 +417,7 @@ function (InterfaceTypeDefinitionNode $def): string {
417417
'extend union',
418418
$def->name,
419419
$this->join($def->directives, ' '),
420-
count($def->types ?? []) > 0
420+
count($def->types) > 0
421421
? '= ' . $this->join($def->types, ' | ')
422422
: '',
423423
],

src/Type/Definition/Directive.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Directive
3232
/** @var string|null */
3333
public $description;
3434

35-
/** @var FieldArgument[] */
35+
/** @var array<int, FieldArgument> */
3636
public $args = [];
3737

3838
/** @var bool */

src/Type/Definition/EnumType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class EnumType extends Type implements InputType, OutputType, LeafType, Nullable
4444
/** @var ArrayObject<string, EnumValueDefinition> */
4545
private $nameLookup;
4646

47-
/** @var EnumTypeExtensionNode[] */
47+
/** @var array<int, EnumTypeExtensionNode> */
4848
public $extensionASTNodes;
4949

5050
public function __construct($config)
@@ -58,7 +58,7 @@ public function __construct($config)
5858
$this->name = $config['name'];
5959
$this->description = $config['description'] ?? null;
6060
$this->astNode = $config['astNode'] ?? null;
61-
$this->extensionASTNodes = $config['extensionASTNodes'] ?? null;
61+
$this->extensionASTNodes = $config['extensionASTNodes'] ?? [];
6262
$this->config = $config;
6363
}
6464

src/Type/Definition/FieldArgument.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public function __construct(array $def)
5858
}
5959

6060
/**
61-
* @param mixed[] $config
61+
* @param array<mixed> $config
6262
*
63-
* @return FieldArgument[]
63+
* @return array<int, FieldArgument>
6464
*/
6565
public static function createMap(array $config): array
6666
{

src/Type/Definition/FieldDefinition.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FieldDefinition
2626
/** @var string */
2727
public $name;
2828

29-
/** @var FieldArgument[] */
29+
/** @var array<int, FieldArgument> */
3030
public $args;
3131

3232
/**
@@ -169,14 +169,9 @@ public static function defaultComplexity($childrenComplexity)
169169
return $childrenComplexity + 1;
170170
}
171171

172-
/**
173-
* @param string $name
174-
*
175-
* @return FieldArgument|null
176-
*/
177-
public function getArg($name)
172+
public function getArg(string $name): ?FieldArgument
178173
{
179-
foreach ($this->args ?? [] as $arg) {
174+
foreach ($this->args as $arg) {
180175
/** @var FieldArgument $arg */
181176
if ($arg->name === $name) {
182177
return $arg;

src/Type/Definition/InputObjectType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class InputObjectType extends Type implements InputType, NullableType, NamedType
2727
*/
2828
private $fields;
2929

30-
/** @var InputObjectTypeExtensionNode[] */
30+
/** @var array<int, InputObjectTypeExtensionNode> */
3131
public $extensionASTNodes;
3232

3333
/**
@@ -45,7 +45,7 @@ public function __construct(array $config)
4545
$this->name = $config['name'];
4646
$this->astNode = $config['astNode'] ?? null;
4747
$this->description = $config['description'] ?? null;
48-
$this->extensionASTNodes = $config['extensionASTNodes'] ?? null;
48+
$this->extensionASTNodes = $config['extensionASTNodes'] ?? [];
4949
}
5050

5151
/**

src/Type/Definition/InterfaceType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(array $config)
5959
$this->name = $config['name'];
6060
$this->description = $config['description'] ?? null;
6161
$this->astNode = $config['astNode'] ?? null;
62-
$this->extensionASTNodes = $config['extensionASTNodes'] ?? null;
62+
$this->extensionASTNodes = $config['extensionASTNodes'] ?? [];
6363
$this->config = $config;
6464
}
6565

0 commit comments

Comments
 (0)