Skip to content

Commit 3c37c51

Browse files
authored
Make type hint for OperationDefinitionNode#name nullable (#653)
1 parent 2f72dd6 commit 3c37c51

7 files changed

Lines changed: 14 additions & 35 deletions

File tree

phpstan-baseline.neon

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,6 @@ parameters:
300300
count: 18
301301
path: src/Language/Printer.php
302302

303-
-
304-
message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Language\\\\AST\\\\NameNode given\\.$#"
305-
count: 1
306-
path: src/Language/Printer.php
307-
308303
-
309304
message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\NameNode\"\\.$#"
310305
count: 1
@@ -1155,11 +1150,6 @@ parameters:
11551150
count: 1
11561151
path: src/Validator/Rules/LoneAnonymousOperation.php
11571152

1158-
-
1159-
message: "#^Only booleans are allowed in \\|\\|, GraphQL\\\\Language\\\\AST\\\\NameNode given on the left side\\.$#"
1160-
count: 1
1161-
path: src/Validator/Rules/LoneAnonymousOperation.php
1162-
11631153
-
11641154
message: "#^Anonymous function should have native return typehint \"void\"\\.$#"
11651155
count: 1
@@ -1190,11 +1180,6 @@ parameters:
11901180
count: 1
11911181
path: src/Validator/Rules/NoUndefinedVariables.php
11921182

1193-
-
1194-
message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\NameNode given\\.$#"
1195-
count: 1
1196-
path: src/Validator/Rules/NoUndefinedVariables.php
1197-
11981183
-
11991184
message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\VisitorOperation\"\\.$#"
12001185
count: 2
@@ -1215,11 +1200,6 @@ parameters:
12151200
count: 3
12161201
path: src/Validator/Rules/NoUnusedVariables.php
12171202

1218-
-
1219-
message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\NameNode given\\.$#"
1220-
count: 1
1221-
path: src/Validator/Rules/NoUnusedVariables.php
1222-
12231203
-
12241204
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
12251205
count: 1
@@ -1460,11 +1440,6 @@ parameters:
14601440
count: 2
14611441
path: src/Validator/Rules/UniqueOperationNames.php
14621442

1463-
-
1464-
message: "#^Only booleans are allowed in an if condition, GraphQL\\\\Language\\\\AST\\\\NameNode given\\.$#"
1465-
count: 1
1466-
path: src/Validator/Rules/UniqueOperationNames.php
1467-
14681443
-
14691444
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
14701445
count: 1
@@ -1496,22 +1471,22 @@ parameters:
14961471
path: src/Validator/Rules/ValuesOfCorrectType.php
14971472

14981473
-
1499-
message: "#^Only booleans are allowed in \\|\\|, GraphQL\\\\Type\\\\Definition\\\\EnumType\\|GraphQL\\\\Type\\\\Definition\\\\InputObjectType\\|GraphQL\\\\Type\\\\Definition\\\\ListOfType\\|GraphQL\\\\Type\\\\Definition\\\\NonNull\\|GraphQL\\\\Type\\\\Definition\\\\ScalarType given on the left side\\.$#"
1474+
message: "#^Anonymous function should have native return typehint \"string\"\\.$#"
15001475
count: 1
15011476
path: src/Validator/Rules/ValuesOfCorrectType.php
15021477

15031478
-
1504-
message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\EnumValueDefinition\\|null given\\.$#"
1479+
message: "#^Only booleans are allowed in \\|\\|, GraphQL\\\\Type\\\\Definition\\\\EnumType\\|GraphQL\\\\Type\\\\Definition\\\\InputObjectType\\|GraphQL\\\\Type\\\\Definition\\\\ListOfType\\|GraphQL\\\\Type\\\\Definition\\\\NonNull\\|GraphQL\\\\Type\\\\Definition\\\\ScalarType given on the left side\\.$#"
15051480
count: 1
15061481
path: src/Validator/Rules/ValuesOfCorrectType.php
15071482

15081483
-
1509-
message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\EnumType\\|GraphQL\\\\Type\\\\Definition\\\\InputObjectType\\|GraphQL\\\\Type\\\\Definition\\\\ListOfType\\|GraphQL\\\\Type\\\\Definition\\\\NonNull\\|GraphQL\\\\Type\\\\Definition\\\\ScalarType given\\.$#"
1484+
message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\EnumValueDefinition\\|null given\\.$#"
15101485
count: 1
15111486
path: src/Validator/Rules/ValuesOfCorrectType.php
15121487

15131488
-
1514-
message: "#^Anonymous function should have native return typehint \"string\"\\.$#"
1489+
message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\EnumType\\|GraphQL\\\\Type\\\\Definition\\\\InputObjectType\\|GraphQL\\\\Type\\\\Definition\\\\ListOfType\\|GraphQL\\\\Type\\\\Definition\\\\NonNull\\|GraphQL\\\\Type\\\\Definition\\\\ScalarType given\\.$#"
15151490
count: 1
15161491
path: src/Validator/Rules/ValuesOfCorrectType.php
15171492

src/Language/AST/OperationDefinitionNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class OperationDefinitionNode extends Node implements ExecutableDefinitionNode,
99
/** @var string */
1010
public $kind = NodeKind::OPERATION_DEFINITION;
1111

12-
/** @var NameNode */
12+
/** @var NameNode|null */
1313
public $name;
1414

1515
/** @var string (oneOf 'query', 'mutation')) */

src/Language/Printer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function printAST($ast)
120120

121121
// Anonymous queries with no directives or variable definitions can use
122122
// the query short form.
123-
return ! $name && ! $directives && ! $varDefs && $op === 'query'
123+
return $name === null && ! $directives && ! $varDefs && $op === 'query'
124124
? $selectionSet
125125
: $this->join([$op, $this->join([$name, $varDefs]), $directives, $selectionSet], ' ');
126126
},

src/Validator/Rules/LoneAnonymousOperation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static function (Node $definition) {
4040
&$operationCount,
4141
$context
4242
) {
43-
if ($node->name || $operationCount <= 1) {
43+
if ($node->name !== null || $operationCount <= 1) {
4444
return;
4545
}
4646

src/Validator/Rules/NoUndefinedVariables.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public function getVisitor(ValidationContext $context)
4040
$context->reportError(new Error(
4141
self::undefinedVarMessage(
4242
$varName,
43-
$operation->name ? $operation->name->value : null
43+
$operation->name !== null
44+
? $operation->name->value
45+
: null
4446
),
4547
[$node, $operation]
4648
));

src/Validator/Rules/NoUnusedVariables.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public function getVisitor(ValidationContext $context)
2828
'leave' => function (OperationDefinitionNode $operation) use ($context) {
2929
$variableNameUsed = [];
3030
$usages = $context->getRecursiveVariableUsages($operation);
31-
$opName = $operation->name ? $operation->name->value : null;
31+
$opName = $operation->name !== null
32+
? $operation->name->value
33+
: null;
3234

3335
foreach ($usages as $usage) {
3436
$node = $usage['node'];

src/Validator/Rules/UniqueOperationNames.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function getVisitor(ValidationContext $context)
2525
NodeKind::OPERATION_DEFINITION => function (OperationDefinitionNode $node) use ($context) {
2626
$operationName = $node->name;
2727

28-
if ($operationName) {
28+
if ($operationName !== null) {
2929
if (empty($this->knownOperationNames[$operationName->value])) {
3030
$this->knownOperationNames[$operationName->value] = $operationName;
3131
} else {

0 commit comments

Comments
 (0)