Skip to content

Commit

Permalink
Fix the @var type hint for various NodeList<Node> usages.
Browse files Browse the repository at this point in the history
- Remove ` = []` from a couple of usages, as this is now considered invalid typing.
- Adjust a few boolean validations to explicitly check for ` === null` now (the default when not set during manual construction).
  • Loading branch information
zimzat committed Sep 1, 2020
1 parent 4f34309 commit 7fecf69
Show file tree
Hide file tree
Showing 27 changed files with 43 additions and 58 deletions.
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -310,21 +310,11 @@ parameters:
count: 1
path: src/Utils/ASTDefinitionBuilder.php

-
message: "#^Only booleans are allowed in an if condition, array\\<GraphQL\\\\Language\\\\AST\\\\NamedTypeNode\\> given\\.$#"
count: 1
path: src/Utils/ASTDefinitionBuilder.php

-
message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\NodeList\\<GraphQL\\\\Language\\\\AST\\\\EnumValueDefinitionNode\\>\\|null given\\.$#"
count: 1
path: src/Utils/ASTDefinitionBuilder.php

-
message: "#^Only booleans are allowed in a ternary operator condition, array\\<GraphQL\\\\Language\\\\AST\\\\InputValueDefinitionNode\\>\\|null given\\.$#"
count: 1
path: src/Utils/ASTDefinitionBuilder.php

-
message: "#^Only booleans are allowed in &&, array\\<bool\\>\\|null given on the left side\\.$#"
count: 1
Expand All @@ -340,11 +330,6 @@ parameters:
count: 1
path: src/Utils/SchemaExtender.php

-
message: "#^Only booleans are allowed in a negated boolean, array\\<GraphQL\\\\Language\\\\AST\\\\OperationTypeDefinitionNode\\>\\|null given\\.$#"
count: 1
path: src/Utils/SchemaExtender.php

-
message: "#^Only booleans are allowed in a negated boolean, array\\<GraphQL\\\\Type\\\\Definition\\\\Type\\>\\|null given\\.$#"
count: 1
Expand Down
4 changes: 2 additions & 2 deletions src/Language/AST/DirectiveDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class DirectiveDefinitionNode extends Node implements TypeSystemDefinitionNode
/** @var StringValueNode|null */
public $description;

/** @var InputValueDefinitionNode[] */
/** @var NodeList<InputValueDefinitionNode> */
public $arguments;

/** @var bool */
public $repeatable;

/** @var NameNode[] */
/** @var NodeList<NameNode> */
public $locations;
}
2 changes: 1 addition & 1 deletion src/Language/AST/DirectiveNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class DirectiveNode extends Node
/** @var NameNode */
public $name;

/** @var ArgumentNode[] */
/** @var NodeList<ArgumentNode> */
public $arguments;
}
2 changes: 1 addition & 1 deletion src/Language/AST/EnumTypeDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EnumTypeDefinitionNode extends Node implements TypeDefinitionNode
/** @var NameNode */
public $name;

/** @var DirectiveNode[] */
/** @var NodeList<DirectiveNode> */
public $directives;

/** @var NodeList<EnumValueDefinitionNode>|null */
Expand Down
4 changes: 2 additions & 2 deletions src/Language/AST/EnumTypeExtensionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class EnumTypeExtensionNode extends Node implements TypeExtensionNode
/** @var NameNode */
public $name;

/** @var DirectiveNode[]|null */
/** @var NodeList<DirectiveNode>|null */
public $directives;

/** @var EnumValueDefinitionNode[]|null */
/** @var NodeList<EnumValueDefinitionNode>|null */
public $values;
}
2 changes: 1 addition & 1 deletion src/Language/AST/EnumValueDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EnumValueDefinitionNode extends Node
/** @var NameNode */
public $name;

/** @var DirectiveNode[] */
/** @var NodeList<DirectiveNode> */
public $directives;

/** @var StringValueNode|null */
Expand Down
4 changes: 2 additions & 2 deletions src/Language/AST/FieldNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class FieldNode extends Node implements SelectionNode
/** @var NameNode|null */
public $alias;

/** @var ArgumentNode[]|null */
/** @var NodeList<ArgumentNode>|null */
public $arguments;

/** @var DirectiveNode[]|null */
/** @var NodeList<DirectiveNode>|null */
public $directives;

/** @var SelectionSetNode|null */
Expand Down
2 changes: 1 addition & 1 deletion src/Language/AST/FragmentSpreadNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class FragmentSpreadNode extends Node implements SelectionNode
/** @var NameNode */
public $name;

/** @var DirectiveNode[] */
/** @var NodeList<DirectiveNode> */
public $directives;
}
2 changes: 1 addition & 1 deletion src/Language/AST/InlineFragmentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class InlineFragmentNode extends Node implements SelectionNode
/** @var NamedTypeNode */
public $typeCondition;

/** @var DirectiveNode[]|null */
/** @var NodeList<DirectiveNode>|null */
public $directives;

/** @var SelectionSetNode */
Expand Down
4 changes: 2 additions & 2 deletions src/Language/AST/InputObjectTypeDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class InputObjectTypeDefinitionNode extends Node implements TypeDefinitionNode
/** @var NameNode */
public $name;

/** @var DirectiveNode[]|null */
/** @var NodeList<DirectiveNode>|null */
public $directives;

/** @var InputValueDefinitionNode[]|null */
/** @var NodeList<InputValueDefinitionNode>|null */
public $fields;

/** @var StringValueNode|null */
Expand Down
4 changes: 2 additions & 2 deletions src/Language/AST/InputObjectTypeExtensionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class InputObjectTypeExtensionNode extends Node implements TypeExtensionNode
/** @var NameNode */
public $name;

/** @var DirectiveNode[]|null */
/** @var NodeList<DirectiveNode>|null */
public $directives;

/** @var InputValueDefinitionNode[]|null */
/** @var NodeList<InputValueDefinitionNode>|null */
public $fields;
}
2 changes: 1 addition & 1 deletion src/Language/AST/InputValueDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class InputValueDefinitionNode extends Node
/** @var VariableNode|NullValueNode|IntValueNode|FloatValueNode|StringValueNode|BooleanValueNode|EnumValueNode|ListValueNode|ObjectValueNode|null */
public $defaultValue;

/** @var DirectiveNode[] */
/** @var NodeList<DirectiveNode> */
public $directives;

/** @var StringValueNode|null */
Expand Down
4 changes: 2 additions & 2 deletions src/Language/AST/InterfaceTypeDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class InterfaceTypeDefinitionNode extends Node implements TypeDefinitionNode
/** @var NameNode */
public $name;

/** @var DirectiveNode[]|null */
/** @var NodeList<DirectiveNode>|null */
public $directives;

/** @var FieldDefinitionNode[]|null */
/** @var NodeList<FieldDefinitionNode>|null */
public $fields;

/** @var StringValueNode|null */
Expand Down
4 changes: 2 additions & 2 deletions src/Language/AST/InterfaceTypeExtensionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class InterfaceTypeExtensionNode extends Node implements TypeExtensionNode
/** @var NameNode */
public $name;

/** @var DirectiveNode[]|null */
/** @var NodeList<DirectiveNode>|null */
public $directives;

/** @var FieldDefinitionNode[]|null */
/** @var NodeList<FieldDefinitionNode>|null */
public $fields;
}
8 changes: 4 additions & 4 deletions src/Language/AST/ObjectTypeDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class ObjectTypeDefinitionNode extends Node implements TypeDefinitionNode
/** @var NameNode */
public $name;

/** @var NamedTypeNode[] */
public $interfaces = [];
/** @var NodeList<NamedTypeNode> */
public $interfaces;

/** @var DirectiveNode[]|null */
/** @var NodeList<DirectiveNode> */
public $directives;

/** @var FieldDefinitionNode[]|null */
/** @var NodeList<FieldDefinitionNode>|null */
public $fields;

/** @var StringValueNode|null */
Expand Down
8 changes: 4 additions & 4 deletions src/Language/AST/ObjectTypeExtensionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class ObjectTypeExtensionNode extends Node implements TypeExtensionNode
/** @var NameNode */
public $name;

/** @var NamedTypeNode[] */
public $interfaces = [];
/** @var NodeList<NamedTypeNode> */
public $interfaces;

/** @var DirectiveNode[] */
/** @var NodeList<DirectiveNode> */
public $directives;

/** @var FieldDefinitionNode[] */
/** @var NodeList<FieldDefinitionNode> */
public $fields;
}
4 changes: 2 additions & 2 deletions src/Language/AST/OperationDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class OperationDefinitionNode extends Node implements ExecutableDefinitionNode,
/** @var string (oneOf 'query', 'mutation')) */
public $operation;

/** @var VariableDefinitionNode[] */
/** @var NodeList<VariableDefinitionNode> */
public $variableDefinitions;

/** @var DirectiveNode[] */
/** @var NodeList<DirectiveNode> */
public $directives;

/** @var SelectionSetNode */
Expand Down
2 changes: 1 addition & 1 deletion src/Language/AST/ScalarTypeDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ScalarTypeDefinitionNode extends Node implements TypeDefinitionNode
/** @var NameNode */
public $name;

/** @var DirectiveNode[] */
/** @var NodeList<DirectiveNode> */
public $directives;

/** @var StringValueNode|null */
Expand Down
2 changes: 1 addition & 1 deletion src/Language/AST/ScalarTypeExtensionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class ScalarTypeExtensionNode extends Node implements TypeExtensionNode
/** @var NameNode */
public $name;

/** @var DirectiveNode[]|null */
/** @var NodeList<DirectiveNode>|null */
public $directives;
}
4 changes: 2 additions & 2 deletions src/Language/AST/SchemaDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class SchemaDefinitionNode extends Node implements TypeSystemDefinitionNode
/** @var string */
public $kind = NodeKind::SCHEMA_DEFINITION;

/** @var DirectiveNode[] */
/** @var NodeList<DirectiveNode> */
public $directives;

/** @var OperationTypeDefinitionNode[] */
/** @var NodeList<OperationTypeDefinitionNode> */
public $operationTypes;
}
4 changes: 2 additions & 2 deletions src/Language/AST/SchemaTypeExtensionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class SchemaTypeExtensionNode extends Node implements TypeExtensionNode
/** @var string */
public $kind = NodeKind::SCHEMA_EXTENSION;

/** @var DirectiveNode[]|null */
/** @var NodeList<DirectiveNode>|null */
public $directives;

/** @var OperationTypeDefinitionNode[]|null */
/** @var NodeList<OperationTypeDefinitionNode>|null */
public $operationTypes;
}
2 changes: 1 addition & 1 deletion src/Language/AST/SelectionSetNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class SelectionSetNode extends Node
/** @var string */
public $kind = NodeKind::SELECTION_SET;

/** @var SelectionNode[] */
/** @var NodeList<SelectionNode&Node> */
public $selections;
}
2 changes: 1 addition & 1 deletion src/Language/AST/UnionTypeDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UnionTypeDefinitionNode extends Node implements TypeDefinitionNode
/** @var NameNode */
public $name;

/** @var DirectiveNode[] */
/** @var NodeList<DirectiveNode> */
public $directives;

/** @var NodeList<NamedTypeNode>|null */
Expand Down
2 changes: 1 addition & 1 deletion src/Language/AST/UnionTypeExtensionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UnionTypeExtensionNode extends Node implements TypeExtensionNode
/** @var NameNode */
public $name;

/** @var DirectiveNode[]|null */
/** @var NodeList<DirectiveNode>|null */
public $directives;

/** @var NodeList<NamedTypeNode>|null */
Expand Down
2 changes: 1 addition & 1 deletion src/Language/AST/VariableDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class VariableDefinitionNode extends Node implements DefinitionNode
/** @var VariableNode|NullValueNode|IntValueNode|FloatValueNode|StringValueNode|BooleanValueNode|EnumValueNode|ListValueNode|ObjectValueNode|null */
public $defaultValue;

/** @var DirectiveNode[] */
/** @var NodeList<DirectiveNode> */
public $directives;
}
4 changes: 2 additions & 2 deletions src/Utils/ASTDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private function getDeprecationReason($node)

private function makeImplementedInterfaces(ObjectTypeDefinitionNode $def)
{
if ($def->interfaces) {
if ($def->interfaces !== null) {
// Note: While this could make early assertions to get the correctly
// typed values, that would throw immediately while type system
// validation with validateSchema() will produce more actionable results.
Expand Down Expand Up @@ -424,7 +424,7 @@ private function makeInputObjectDef(InputObjectTypeDefinitionNode $def)
'name' => $def->name->value,
'description' => $this->getDescription($def),
'fields' => function () use ($def) {
return $def->fields
return $def->fields !== null
? $this->makeInputValues($def->fields)
: [];
},
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/SchemaExtender.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ static function (string $typeName) use ($schema) {
}

foreach ($schemaExtensions as $schemaExtension) {
if (! $schemaExtension->operationTypes) {
if ($schemaExtension->operationTypes === null) {
continue;
}

Expand Down

0 comments on commit 7fecf69

Please sign in to comment.