Skip to content

Make VisitorArray shape explicit #1675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 97 additions & 2 deletions docs/class-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,103 @@ visitor API:
]
]);

@phpstan-type NodeVisitor callable(Node): (VisitorOperation|null|false|void)
@phpstan-type VisitorArray array<string, NodeVisitor>|array<string, array<string, NodeVisitor>>
@phpstan-type VisitorReturnType Node|VisitorOperation|null|false|void
@phpstan-type VisitorArray array{
enter?: callable(Node, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(Node, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
Name?: array{
enter?: callable(NameNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(NameNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(NameNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
Document?: array{
enter?: callable(DocumentNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(DocumentNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(DocumentNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
OperationDefinition?: array{
enter?: callable(OperationDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(OperationDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(OperationDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
VariableDefinition?: array{
enter?: callable(VariableDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(VariableDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(VariableDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
SchemaDefinition?: array{
enter?: callable(SchemaDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(SchemaDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(SchemaDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
OperationTypeDefinition?: array{
enter?: callable(OperationTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(OperationTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(OperationTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
ScalarTypeDefinition?: array{
enter?: callable(ScalarTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(ScalarTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(ScalarTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
ObjectTypeDefinition?: array{
enter?: callable(ObjectTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(ObjectTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(ObjectTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
FieldDefinition?: array{
enter?: callable(FieldDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(FieldDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(FieldDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
InputValueDefinition?: array{
enter?: callable(InputValueDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(InputValueDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(InputValueDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
InterfaceTypeDefinition?: array{
enter?: callable(InterfaceTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(InterfaceTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(InterfaceTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
UnionTypeDefinition?: array{
enter?: callable(UnionTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(UnionTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(UnionTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
EnumTypeDefinition?: array{
enter?: callable(EnumTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(EnumTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(EnumTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
EnumValueDefinition?: array{
enter?: callable(EnumValueDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(EnumValueDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(EnumValueDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
InputObjectTypeDefinition?: array{
enter?: callable(InputObjectTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(InputObjectTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(InputObjectTypeDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
SchemaExtension?: array{
enter?: callable(SchemaExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(SchemaExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(SchemaExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
DirectiveDefinition?: array{
enter?: callable(DirectiveDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(DirectiveDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(DirectiveDefinitionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
ScalarTypeExtension?: array{
enter?: callable(ScalarTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(ScalarTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(ScalarTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
ObjectTypeExtension?: array{
enter?: callable(ObjectTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(ObjectTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(ObjectTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
InterfaceTypeExtension?: array{
enter?: callable(InterfaceTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(InterfaceTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(InterfaceTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
UnionTypeExtension?: array{
enter?: callable(UnionTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(UnionTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(UnionTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
EnumTypeExtension?: array{
enter?: callable(EnumTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(EnumTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(EnumTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
InputObjectTypeExtension?: array{
enter?: callable(InputObjectTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
leave?: callable(InputObjectTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}|callable(InputObjectTypeExtensionNode, string, null|Node|NodeList, array<int, int|string>, array<int, Node|NodeList>): VisitorReturnType,
}

@see \GraphQL\Tests\Language\VisitorTest

Expand Down
7 changes: 1 addition & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ parameters:
count: 1
path: src/Utils/AST.php

-
message: "#^Method GraphQL\\\\Validator\\\\Rules\\\\KnownDirectives\\:\\:getDirectiveLocationForASTPath\\(\\) has parameter \\$ancestors with generic class GraphQL\\\\Language\\\\AST\\\\NodeList but does not specify its types\\: T$#"
count: 1
path: src/Validator/Rules/KnownDirectives.php

-
message: "#^Method GraphQL\\\\Validator\\\\Rules\\\\OverlappingFieldsCanBeMerged\\:\\:getFieldsAndFragmentNames\\(\\) should return array\\{array\\<string, array\\<int, array\\{GraphQL\\\\Type\\\\Definition\\\\Type, GraphQL\\\\Language\\\\AST\\\\FieldNode, GraphQL\\\\Type\\\\Definition\\\\FieldDefinition\\|null\\}\\>\\>, array\\<int, string\\>\\} but returns array\\{mixed, array\\<int, int\\|string\\>\\}\\.$#"
count: 1
Expand All @@ -88,4 +83,4 @@ parameters:
-
message: "#^SplObjectStorage\\<GraphQL\\\\Language\\\\AST\\\\SelectionSetNode, array\\{array\\<string, array\\<int, array\\{GraphQL\\\\Type\\\\Definition\\\\Type, GraphQL\\\\Language\\\\AST\\\\FieldNode, GraphQL\\\\Type\\\\Definition\\\\FieldDefinition\\|null\\}\\>\\>, array\\<int, string\\>\\}\\> does not accept array\\<int, mixed\\>\\.$#"
count: 1
path: src/Validator/Rules/OverlappingFieldsCanBeMerged.php
path: src/Validator/Rules/OverlappingFieldsCanBeMerged.php
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ parameters:
- message: "#^Property GraphQL\\\\Tests\\\\Type\\\\SchemaTest\\:\\:\\$implementingType is never read, only written\\.$#"
path: tests

# Cannot satisfy input covariance
- '~(expects|should return) array<string, array<string, callable\(GraphQL\\Language\\AST\\Node\): \(GraphQL\\Language\\VisitorOperation\|void\|false\|null\)>\|\(callable\(GraphQL\\Language\\AST\\Node\): \(GraphQL\\Language\\VisitorOperation\|void\|false\|null\)\)>(,| but returns)?~'

# No need to have @throws in methods that are never called
## PHPUnit
- message: "~Method GraphQL\\\\Tests\\\\.+?Test(CaseBase)?::(test.+?|setUp(BeforeClass)?|tearDown)\\(\\) throws checked exception .+? but it's missing from the PHPDoc @throws tag~"
Expand Down
2 changes: 1 addition & 1 deletion src/Language/AST/NodeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use GraphQL\Utils\AST;

/**
* @template T of Node
* @template T of Node = Node
*
* @phpstan-implements \ArrayAccess<array-key, T>
* @phpstan-implements \IteratorAggregate<array-key, T>
Expand Down
Loading