diff --git a/composer.json b/composer.json index 6588612e4..3289dc143 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "doctrine/coding-standard": "^6.0", "phpbench/phpbench": "^0.14", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "0.12.11", + "phpstan/phpstan": "0.12.18", "phpstan/phpstan-phpunit": "0.12.6", "phpstan/phpstan-strict-rules": "0.12.2", "phpunit/phpunit": "^7.2|^8.5", @@ -54,7 +54,7 @@ "lint" : "phpcs", "fix" : "phpcbf", "stan": "phpstan analyse --ansi --memory-limit 2048M", - "phpstan-baseline": "phpstan analyse --ansi --error-format baselineNeon > phpstan-baseline.neon", + "phpstan-baseline": "phpstan analyse --ansi --generate-baseline=phpstan-baseline.neon", "check": "composer lint && composer stan && composer test" } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1be9308e7..8565ae099 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -50,11 +50,6 @@ parameters: count: 1 path: src/Error/Error.php - - - message: "#^Anonymous function should have native return typehint \"\\?GraphQL\\\\Language\\\\SourceLocation\"\\.$#" - count: 1 - path: src/Error/Error.php - - message: "#^Only booleans are allowed in &&, GraphQL\\\\Language\\\\AST\\\\Location given on the left side\\.$#" count: 1 @@ -160,11 +155,6 @@ parameters: count: 4 path: src/Executor/ReferenceExecutor.php - - - message: "#^Anonymous function should have native return typehint \"\\?GraphQL\\\\Type\\\\Definition\\\\ObjectType\"\\.$#" - count: 1 - path: src/Executor/ReferenceExecutor.php - - message: "#^Only booleans are allowed in &&, GraphQL\\\\Language\\\\AST\\\\BooleanValueNode\\|GraphQL\\\\Language\\\\AST\\\\EnumValueNode\\|GraphQL\\\\Language\\\\AST\\\\FloatValueNode\\|GraphQL\\\\Language\\\\AST\\\\IntValueNode\\|GraphQL\\\\Language\\\\AST\\\\ListValueNode\\|GraphQL\\\\Language\\\\AST\\\\NullValueNode\\|GraphQL\\\\Language\\\\AST\\\\ObjectValueNode\\|GraphQL\\\\Language\\\\AST\\\\StringValueNode\\|GraphQL\\\\Language\\\\AST\\\\VariableNode\\|null given on the right side\\.$#" count: 1 @@ -200,11 +190,6 @@ parameters: count: 2 path: src/Experimental/Executor/CoroutineExecutor.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 3 - path: src/Experimental/Executor/CoroutineExecutor.php - - message: "#^Variable property access on object\\.$#" count: 2 @@ -225,11 +210,6 @@ parameters: count: 2 path: src/GraphQL.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: src/GraphQL.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 @@ -255,61 +235,11 @@ parameters: count: 1 path: src/Language/Parser.php - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\VariableDefinitionNode\"\\.$#" - count: 1 - path: src/Language/Parser.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\SelectionNode\"\\.$#" - count: 1 - path: src/Language/Parser.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\ArgumentNode\"\\.$#" - count: 2 - path: src/Language/Parser.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\OperationTypeDefinitionNode\"\\.$#" - count: 1 - path: src/Language/Parser.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\FieldDefinitionNode\"\\.$#" - count: 1 - path: src/Language/Parser.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\InputValueDefinitionNode\"\\.$#" - count: 2 - path: src/Language/Parser.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\EnumValueDefinitionNode\"\\.$#" - count: 1 - path: src/Language/Parser.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 1 path: src/Language/Printer.php - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 18 - path: src/Language/Printer.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\AST\\\\NameNode\"\\.$#" - count: 1 - path: src/Language/Printer.php - - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 3 - path: src/Language/Printer.php - - message: "#^Only booleans are allowed in a ternary operator condition, array\\\\|null given\\.$#" count: 2 @@ -395,21 +325,11 @@ parameters: count: 5 path: src/Server/Helper.php - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Error\\\\Error\"\\.$#" - count: 1 - path: src/Server/Helper.php - - message: "#^Only booleans are allowed in a ternary operator condition, string given\\.$#" count: 1 path: src/Server/Helper.php - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Executor\\\\ExecutionResult\"\\.$#" - count: 1 - path: src/Server/Helper.php - - message: "#^Only booleans are allowed in an if condition, \\(callable\\)\\|null given\\.$#" count: 1 @@ -420,11 +340,6 @@ parameters: count: 1 path: src/Server/Helper.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: src/Server/Helper.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 2 @@ -470,11 +385,6 @@ parameters: count: 1 path: src/Type/Definition/ObjectType.php - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 2 - path: src/Type/Definition/QueryPlan.php - - message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Language\\\\AST\\\\SelectionSetNode\\|null given\\.$#" count: 1 @@ -495,61 +405,21 @@ parameters: count: 1 path: src/Type/Definition/Type.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 3 - path: src/Type/Introspection.php - - - - message: "#^Anonymous function should have native return typehint \"\\?GraphQL\\\\Type\\\\Definition\\\\ObjectType\"\\.$#" - count: 2 - path: src/Type/Introspection.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 3 path: src/Type/Introspection.php - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 4 - path: src/Type/Introspection.php - - message: "#^Only booleans are allowed in a negated boolean, string\\|null given\\.$#" count: 2 path: src/Type/Introspection.php - - - message: "#^Anonymous function should have native return typehint \"\\?array\"\\.$#" - count: 3 - path: src/Type/Introspection.php - - - - message: "#^Anonymous function should have native return typehint \"\\?GraphQL\\\\Type\\\\Definition\\\\Type\"\\.$#" - count: 2 - path: src/Type/Introspection.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 3 - path: src/Type/Introspection.php - - - - message: "#^Anonymous function should have native return typehint \"\\?string\"\\.$#" - count: 4 - path: src/Type/Introspection.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 1 path: src/Type/Introspection.php - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Schema\"\\.$#" - count: 1 - path: src/Type/Introspection.php - - message: "#^Only booleans are allowed in a negated boolean, array\\\\|\\(callable\\) given\\.$#" count: 1 @@ -610,21 +480,11 @@ parameters: count: 1 path: src/Type/SchemaValidationContext.php - - - message: "#^Anonymous function should have native return typehint \"\\?GraphQL\\\\Language\\\\AST\\\\DirectiveDefinitionNode\"\\.$#" - count: 1 - path: src/Type/SchemaValidationContext.php - - message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Error\\\\Error\\|null given\\.$#" count: 1 path: src/Type/SchemaValidationContext.php - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 6 - path: src/Type/SchemaValidationContext.php - - message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\InputValueDefinitionNode given\\.$#" count: 1 @@ -785,21 +645,11 @@ parameters: count: 1 path: src/Utils/ASTDefinitionBuilder.php - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\Type\"\\.$#" - count: 2 - path: src/Utils/ASTDefinitionBuilder.php - - message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\NodeList\\\\|null given\\.$#" count: 1 path: src/Utils/ASTDefinitionBuilder.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: src/Utils/ASTDefinitionBuilder.php - - message: "#^Only booleans are allowed in a ternary operator condition, array\\\\|null given\\.$#" count: 1 @@ -810,11 +660,6 @@ parameters: count: 1 path: src/Utils/ASTDefinitionBuilder.php - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 2 - path: src/Utils/BreakingChangesFinder.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 1 @@ -825,41 +670,11 @@ parameters: count: 3 path: src/Utils/BuildSchema.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Utils/BuildSchema.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\Type\"\\.$#" - count: 1 - path: src/Utils/BuildSchema.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: src/Utils/BuildSchema.php - - message: "#^Only booleans are allowed in &&, array\\\\|null given on the left side\\.$#" count: 1 path: src/Utils/PairSet.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 5 - path: src/Utils/SchemaExtender.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 1 - path: src/Utils/SchemaExtender.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\Directive\"\\.$#" - count: 1 - path: src/Utils/SchemaExtender.php - - message: "#^Only booleans are allowed in an if condition, GraphQL\\\\Type\\\\Definition\\\\Type\\|null given\\.$#" count: 1 @@ -875,21 +690,6 @@ parameters: count: 1 path: src/Utils/SchemaExtender.php - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\Type\"\\.$#" - count: 1 - path: src/Utils/SchemaExtender.php - - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 3 - path: src/Utils/SchemaPrinter.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 7 - path: src/Utils/SchemaPrinter.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 2 @@ -935,11 +735,6 @@ parameters: count: 1 path: src/Utils/TypeInfo.php - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 1 - path: src/Utils/TypeInfo.php - - message: "#^Only booleans are allowed in &&, GraphQL\\\\Type\\\\Definition\\\\FieldArgument\\|null given on the left side\\.$#" count: 1 @@ -975,26 +770,11 @@ parameters: count: 1 path: src/Utils/Utils.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Utils/Utils.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 2 - path: src/Utils/Utils.php - - message: "#^Only booleans are allowed in an if condition, GraphQL\\\\Type\\\\Definition\\\\EnumValueDefinition\\|null given\\.$#" count: 1 path: src/Utils/Value.php - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 1 - path: src/Utils/Value.php - - message: "#^Only booleans are allowed in a ternary operator condition, array\\ given\\.$#" count: 2 @@ -1020,21 +800,6 @@ parameters: count: 1 path: src/Validator/DocumentValidator.php - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 1 - path: src/Validator/DocumentValidator.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\VisitorOperation\"\\.$#" - count: 1 - path: src/Validator/Rules/ExecutableDefinitions.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/FieldsOnCorrectType.php - - message: "#^Only booleans are allowed in a negated boolean, \\(GraphQL\\\\Type\\\\Definition\\\\CompositeType&GraphQL\\\\Type\\\\Definition\\\\Type\\)\\|null given\\.$#" count: 1 @@ -1055,11 +820,6 @@ parameters: count: 1 path: src/Validator/Rules/FieldsOnCorrectType.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: src/Validator/Rules/FragmentsOnCompositeTypes.php - - message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Language\\\\AST\\\\NamedTypeNode given\\.$#" count: 1 @@ -1070,21 +830,11 @@ parameters: count: 2 path: src/Validator/Rules/FragmentsOnCompositeTypes.php - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 1 - path: src/Validator/Rules/KnownArgumentNames.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 2 path: src/Validator/Rules/KnownArgumentNames.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/KnownArgumentNamesOnDirectives.php - - message: "#^Only booleans are allowed in a negated boolean, array\\\\|null given\\.$#" count: 1 @@ -1105,56 +855,21 @@ parameters: count: 1 path: src/Validator/Rules/KnownDirectives.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/KnownFragmentNames.php - - message: "#^Only booleans are allowed in an if condition, GraphQL\\\\Language\\\\AST\\\\FragmentDefinitionNode\\|null given\\.$#" count: 1 path: src/Validator/Rules/KnownFragmentNames.php - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\VisitorOperation\"\\.$#" - count: 1 - path: src/Validator/Rules/KnownTypeNames.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/KnownTypeNames.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 path: src/Validator/Rules/KnownTypeNames.php - - - message: "#^Anonymous function sometimes return something but return statement at the end is missing\\.$#" - count: 1 - path: src/Validator/Rules/LoneAnonymousOperation.php - - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 1 - path: src/Validator/Rules/LoneAnonymousOperation.php - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" count: 1 path: src/Validator/Rules/LoneAnonymousOperation.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/LoneSchemaDefinition.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\VisitorOperation\"\\.$#" - count: 2 - path: src/Validator/Rules/NoFragmentCycles.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 3 @@ -1165,46 +880,21 @@ parameters: count: 1 path: src/Validator/Rules/NoFragmentCycles.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 3 - path: src/Validator/Rules/NoUndefinedVariables.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 path: src/Validator/Rules/NoUndefinedVariables.php - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\VisitorOperation\"\\.$#" - count: 2 - path: src/Validator/Rules/NoUnusedFragments.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/NoUnusedFragments.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 path: src/Validator/Rules/NoUnusedFragments.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 3 - path: src/Validator/Rules/NoUnusedVariables.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 path: src/Validator/Rules/NoUnusedVariables.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/OverlappingFieldsCanBeMerged.php - - message: "#^Only booleans are allowed in a ternary operator condition, GraphQL\\\\Language\\\\AST\\\\NameNode\\|null given\\.$#" count: 1 @@ -1240,21 +930,6 @@ parameters: count: 3 path: src/Validator/Rules/OverlappingFieldsCanBeMerged.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 2 - path: src/Validator/Rules/OverlappingFieldsCanBeMerged.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 1 - path: src/Validator/Rules/OverlappingFieldsCanBeMerged.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: src/Validator/Rules/PossibleFragmentSpreads.php - - message: "#^Only booleans are allowed in a negated boolean, \\(GraphQL\\\\Type\\\\Definition\\\\CompositeType&GraphQL\\\\Type\\\\Definition\\\\Type\\)\\|null given\\.$#" count: 1 @@ -1265,11 +940,6 @@ parameters: count: 1 path: src/Validator/Rules/PossibleFragmentSpreads.php - - - message: "#^Anonymous function sometimes return something but return statement at the end is missing\\.$#" - count: 2 - path: src/Validator/Rules/ProvidedRequiredArguments.php - - message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\FieldDefinition given\\.$#" count: 1 @@ -1300,11 +970,6 @@ parameters: count: 1 path: src/Validator/Rules/ProvidedRequiredArgumentsOnDirectives.php - - - message: "#^Anonymous function sometimes return something but return statement at the end is missing\\.$#" - count: 1 - path: src/Validator/Rules/ProvidedRequiredArgumentsOnDirectives.php - - message: "#^Only booleans are allowed in a negated boolean, array\\|null given\\.$#" count: 1 @@ -1315,16 +980,6 @@ parameters: count: 1 path: src/Validator/Rules/ProvidedRequiredArgumentsOnDirectives.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: src/Validator/Rules/QueryComplexity.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\VisitorOperation\"\\.$#" - count: 1 - path: src/Validator/Rules/QueryComplexity.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 3 @@ -1335,11 +990,6 @@ parameters: count: 1 path: src/Validator/Rules/QueryComplexity.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/QueryDepth.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 2 @@ -1365,11 +1015,6 @@ parameters: count: 1 path: src/Validator/Rules/QuerySecurityRule.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/ScalarLeafs.php - - message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\OutputType\\|null given\\.$#" count: 1 @@ -1385,66 +1030,26 @@ parameters: count: 1 path: src/Validator/Rules/ScalarLeafs.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: src/Validator/Rules/UniqueArgumentNames.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\VisitorOperation\"\\.$#" - count: 1 - path: src/Validator/Rules/UniqueArgumentNames.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 path: src/Validator/Rules/UniqueArgumentNames.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/UniqueDirectivesPerLocation.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\VisitorOperation\"\\.$#" - count: 2 - path: src/Validator/Rules/UniqueFragmentNames.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 path: src/Validator/Rules/UniqueFragmentNames.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: src/Validator/Rules/UniqueInputFieldNames.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\VisitorOperation\"\\.$#" - count: 1 - path: src/Validator/Rules/UniqueInputFieldNames.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 path: src/Validator/Rules/UniqueInputFieldNames.php - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Language\\\\VisitorOperation\"\\.$#" - count: 2 - path: src/Validator/Rules/UniqueOperationNames.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 path: src/Validator/Rules/UniqueOperationNames.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: src/Validator/Rules/UniqueVariableNames.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 @@ -1455,21 +1060,6 @@ parameters: count: 1 path: src/Validator/Rules/ValidationRule.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 8 - path: src/Validator/Rules/ValuesOfCorrectType.php - - - - message: "#^Anonymous function sometimes return something but return statement at the end is missing\\.$#" - count: 1 - path: src/Validator/Rules/ValuesOfCorrectType.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 1 - path: src/Validator/Rules/ValuesOfCorrectType.php - - 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\\.$#" count: 1 @@ -1490,21 +1080,11 @@ parameters: count: 1 path: src/Validator/Rules/ValuesOfCorrectType.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/Rules/VariablesAreInputTypes.php - - message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\Type\\|null given\\.$#" count: 1 path: src/Validator/Rules/VariablesAreInputTypes.php - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 3 - path: src/Validator/Rules/VariablesInAllowedPosition.php - - message: "#^Only booleans are allowed in a negated boolean, GraphQL\\\\Type\\\\Definition\\\\Type\\|null given\\.$#" count: 1 @@ -1515,16 +1095,6 @@ parameters: count: 1 path: src/Validator/Rules/VariablesInAllowedPosition.php - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" - count: 1 - path: src/Validator/ValidationContext.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: src/Validator/ValidationContext.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 3 @@ -2032,11 +1602,6 @@ parameters: - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 5 - path: tests/Type/QueryPlanTest.php - - - - message: "#^Anonymous function should have native return typehint \"bool\"\\.$#" count: 1 path: tests/Type/QueryPlanTest.php @@ -2045,158 +1610,23 @@ parameters: count: 1 path: tests/Type/QueryPlanTest.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 2 - path: tests/Type/ResolveInfoTest.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 1 - path: tests/Type/SchemaTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: tests/Type/SchemaTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 3 - path: tests/Type/StandardTypesTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 5 - path: tests/Type/TypeLoaderTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 5 - path: tests/Type/TypeLoaderTest.php - - message: "#^Variable property access on \\$this\\(GraphQL\\\\Tests\\\\Type\\\\TypeLoaderTest\\)\\.$#" count: 1 path: tests/Type/TypeLoaderTest.php - - - message: "#^Anonymous function should have native return typehint \"stdClass\"\\.$#" - count: 1 - path: tests/Type/TypeLoaderTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\InterfaceType\"\\.$#" - count: 1 - path: tests/Type/TypeLoaderTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 3 - path: tests/Type/ValidationTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 5 - path: tests/Type/ValidationTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\ListOfType\"\\.$#" - count: 1 - path: tests/Type/ValidationTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\NonNull\"\\.$#" - count: 2 - path: tests/Type/ValidationTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\ObjectType\"\\.$#" - count: 1 - path: tests/Type/ValidationTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\EnumType\"\\.$#" - count: 1 - path: tests/Type/ValidationTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\InputObjectType\"\\.$#" - count: 1 - path: tests/Type/ValidationTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\UnionType\"\\.$#" - count: 1 - path: tests/Type/ValidationTest.php - - - - message: "#^Anonymous function should have native return typehint \"GraphQL\\\\Type\\\\Definition\\\\InterfaceType\"\\.$#" - count: 1 - path: tests/Type/ValidationTest.php - - - - message: "#^Anonymous function should have native return typehint \"\\?GraphQL\\\\Type\\\\Definition\\\\ObjectType\"\\.$#" - count: 1 - path: tests/Type/ValidationTest.php - - message: "#^Only booleans are allowed in a negated boolean, stdClass given\\.$#" count: 1 path: tests/Utils/AstFromValueTest.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 7 - path: tests/Utils/ExtractTypesTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: tests/Utils/MixedStoreTest.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 2 path: tests/Utils/MixedStoreTest.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 5 - path: tests/Utils/SchemaExtenderTest.php - - - - message: "#^Anonymous function should have native return typehint \"string\"\\.$#" - count: 5 - path: tests/Utils/SchemaExtenderTest.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 1 path: tests/Utils/ValueFromAstTest.php - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 3 - path: tests/Validator/OverlappingFieldsCanBeMergedTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 1 - path: tests/Validator/QueryComplexityTest.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 1 - path: tests/Validator/QueryComplexityTest.php - - - - message: "#^Anonymous function should have native return typehint \"array\"\\.$#" - count: 3 - path: tests/Validator/ValidatorTestCase.php - - - - message: "#^Anonymous function should have native return typehint \"void\"\\.$#" - count: 2 - path: tests/Validator/ValidatorTestCase.php - diff --git a/src/Error/Error.php b/src/Error/Error.php index dfa98715e..7e6056fc0 100644 --- a/src/Error/Error.php +++ b/src/Error/Error.php @@ -278,7 +278,7 @@ static function ($pos) use ($source) : SourceLocation { } elseif ($nodes) { $locations = array_filter( array_map( - static function ($node) { + static function ($node) : ?SourceLocation { if ($node->loc && $node->loc->source) { return $node->loc->source->getLocation($node->loc->start); } diff --git a/src/Executor/ReferenceExecutor.php b/src/Executor/ReferenceExecutor.php index 7093fdd58..afcb59434 100644 --- a/src/Executor/ReferenceExecutor.php +++ b/src/Executor/ReferenceExecutor.php @@ -1038,7 +1038,7 @@ private function defaultTypeResolver($value, $contextValue, ResolveInfo $info, A } if (! empty($promisedIsTypeOfResults)) { return $this->exeContext->promiseAdapter->all($promisedIsTypeOfResults) - ->then(static function ($isTypeOfResults) use ($possibleTypes) { + ->then(static function ($isTypeOfResults) use ($possibleTypes) : ?ObjectType { foreach ($isTypeOfResults as $index => $result) { if ($result) { return $possibleTypes[$index]; diff --git a/src/Experimental/Executor/CoroutineExecutor.php b/src/Experimental/Executor/CoroutineExecutor.php index 185f54a74..5a073eb8e 100644 --- a/src/Experimental/Executor/CoroutineExecutor.php +++ b/src/Experimental/Executor/CoroutineExecutor.php @@ -226,7 +226,7 @@ public function doExecute() : Promise $this->run(); if ($this->pending > 0) { - return $this->promiseAdapter->create(function (callable $resolve) { + return $this->promiseAdapter->create(function (callable $resolve) : void { $this->doResolve = $resolve; }); } @@ -313,13 +313,13 @@ private function run() $this->promiseAdapter ->then( $value, - function ($value) use ($strand) { + function ($value) use ($strand) : void { $strand->success = true; $strand->value = $value; $this->queue->enqueue($strand); $this->done(); }, - function (Throwable $throwable) use ($strand) { + function (Throwable $throwable) use ($strand) : void { $strand->success = false; $strand->value = $throwable; $this->queue->enqueue($strand); diff --git a/src/GraphQL.php b/src/GraphQL.php index ef5d7b4be..3b653b6ab 100644 --- a/src/GraphQL.php +++ b/src/GraphQL.php @@ -213,7 +213,7 @@ public static function execute( if ($promiseAdapter instanceof SyncPromiseAdapter) { $result = $promiseAdapter->wait($result)->toArray(); } else { - $result = $result->then(static function (ExecutionResult $r) { + $result = $result->then(static function (ExecutionResult $r) : array { return $r->toArray(); }); } diff --git a/src/Language/AST/IntValueNode.php b/src/Language/AST/IntValueNode.php index 3441b7bc2..0bdab5be0 100644 --- a/src/Language/AST/IntValueNode.php +++ b/src/Language/AST/IntValueNode.php @@ -9,6 +9,6 @@ class IntValueNode extends Node implements ValueNode /** @var string */ public $kind = NodeKind::INT; - /** @var string */ + /** @var mixed */ public $value; } diff --git a/src/Language/AST/NamedTypeNode.php b/src/Language/AST/NamedTypeNode.php index 7a44b2f67..da62aeddf 100644 --- a/src/Language/AST/NamedTypeNode.php +++ b/src/Language/AST/NamedTypeNode.php @@ -9,6 +9,6 @@ class NamedTypeNode extends Node implements TypeNode /** @var string */ public $kind = NodeKind::NAMED_TYPE; - /** @var NameNode */ + /** @var NameNode|string */ public $name; } diff --git a/src/Language/AST/NodeList.php b/src/Language/AST/NodeList.php index 62a776b24..be77b0183 100644 --- a/src/Language/AST/NodeList.php +++ b/src/Language/AST/NodeList.php @@ -83,8 +83,8 @@ public function offsetGet($offset)// : Node } /** - * @param int|string $offset - * @param Node|mixed[] $value + * @param int|string|null $offset + * @param Node|mixed[] $value * * @phpstan-param T|mixed[] $value */ diff --git a/src/Language/Parser.php b/src/Language/Parser.php index b0ccc7b7c..0328fbdb3 100644 --- a/src/Language/Parser.php +++ b/src/Language/Parser.php @@ -550,7 +550,7 @@ private function parseVariableDefinitions() : NodeList return $this->peek(Token::PAREN_L) ? $this->many( Token::PAREN_L, - function () { + function () : VariableDefinitionNode { return $this->parseVariableDefinition(); }, Token::PAREN_R @@ -601,7 +601,7 @@ private function parseSelectionSet() : SelectionSetNode [ 'selections' => $this->many( Token::BRACE_L, - function () { + function () : SelectionNode { return $this->parseSelection(); }, Token::BRACE_R @@ -656,10 +656,10 @@ private function parseField() : FieldNode private function parseArguments(bool $isConst) : NodeList { $parseFn = $isConst - ? function () { + ? function () : ArgumentNode { return $this->parseConstArgument(); } - : function () { + : function () : ArgumentNode { return $this->parseArgument(); }; @@ -1090,7 +1090,7 @@ private function parseSchemaDefinition() : SchemaDefinitionNode $operationTypes = $this->many( Token::BRACE_L, - function () { + function () : OperationTypeDefinitionNode { return $this->parseOperationTypeDefinition(); }, Token::BRACE_R @@ -1207,7 +1207,7 @@ private function parseFieldsDefinition() : NodeList $nodeList = $this->peek(Token::BRACE_L) ? $this->many( Token::BRACE_L, - function () { + function () : FieldDefinitionNode { return $this->parseFieldDefinition(); }, Token::BRACE_R @@ -1250,7 +1250,7 @@ private function parseArgumentsDefinition() : NodeList $nodeList = $this->peek(Token::PAREN_L) ? $this->many( Token::PAREN_L, - function () { + function () : InputValueDefinitionNode { return $this->parseInputValueDefinition(); }, Token::PAREN_R @@ -1382,7 +1382,7 @@ private function parseEnumValuesDefinition() : NodeList $nodeList = $this->peek(Token::BRACE_L) ? $this->many( Token::BRACE_L, - function () { + function () : EnumValueDefinitionNode { return $this->parseEnumValueDefinition(); }, Token::BRACE_R @@ -1440,7 +1440,7 @@ private function parseInputFieldsDefinition() : NodeList $nodeList = $this->peek(Token::BRACE_L) ? $this->many( Token::BRACE_L, - function () { + function () : InputValueDefinitionNode { return $this->parseInputValueDefinition(); }, Token::BRACE_R diff --git a/src/Language/Printer.php b/src/Language/Printer.php index 54b526d55..8e46ac329 100644 --- a/src/Language/Printer.php +++ b/src/Language/Printer.php @@ -99,15 +99,15 @@ public function printAST($ast) $ast, [ 'leave' => [ - NodeKind::NAME => static function (NameNode $node) { + NodeKind::NAME => static function (NameNode $node) : string { return '' . $node->value; }, - NodeKind::VARIABLE => static function (VariableNode $node) { + NodeKind::VARIABLE => static function (VariableNode $node) : string { return '$' . $node->name; }, - NodeKind::DOCUMENT => function (DocumentNode $node) { + NodeKind::DOCUMENT => function (DocumentNode $node) : string { return $this->join($node->definitions, "\n\n") . "\n"; }, @@ -125,7 +125,7 @@ public function printAST($ast) : $this->join([$op, $this->join([$name, $varDefs]), $directives, $selectionSet], ' '); }, - NodeKind::VARIABLE_DEFINITION => function (VariableDefinitionNode $node) { + NodeKind::VARIABLE_DEFINITION => function (VariableDefinitionNode $node) : string { return $node->variable . ': ' . $node->type @@ -152,11 +152,11 @@ public function printAST($ast) ); }, - NodeKind::ARGUMENT => static function (ArgumentNode $node) { + NodeKind::ARGUMENT => static function (ArgumentNode $node) : string { return $node->name . ': ' . $node->value; }, - NodeKind::FRAGMENT_SPREAD => function (FragmentSpreadNode $node) { + NodeKind::FRAGMENT_SPREAD => function (FragmentSpreadNode $node) : string { return '...' . $node->name . $this->wrap(' ', $this->join($node->directives, ' ')); }, @@ -172,7 +172,7 @@ public function printAST($ast) ); }, - NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) { + NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) : string { // Note: fragment variable definitions are experimental and may be changed or removed in the future. return sprintf('fragment %s', $node->name) . $this->wrap('(', $this->join($node->variableDefinitions, ', '), ')') @@ -185,7 +185,7 @@ public function printAST($ast) return $node->value; }, - NodeKind::FLOAT => static function (FloatValueNode $node) { + NodeKind::FLOAT => static function (FloatValueNode $node) : string { return $node->value; }, @@ -201,39 +201,39 @@ public function printAST($ast) return $node->value ? 'true' : 'false'; }, - NodeKind::NULL => static function (NullValueNode $node) { + NodeKind::NULL => static function (NullValueNode $node) : string { return 'null'; }, - NodeKind::ENUM => static function (EnumValueNode $node) { + NodeKind::ENUM => static function (EnumValueNode $node) : string { return $node->value; }, - NodeKind::LST => function (ListValueNode $node) { + NodeKind::LST => function (ListValueNode $node) : string { return '[' . $this->join($node->values, ', ') . ']'; }, - NodeKind::OBJECT => function (ObjectValueNode $node) { + NodeKind::OBJECT => function (ObjectValueNode $node) : string { return '{' . $this->join($node->fields, ', ') . '}'; }, - NodeKind::OBJECT_FIELD => static function (ObjectFieldNode $node) { + NodeKind::OBJECT_FIELD => static function (ObjectFieldNode $node) : string { return $node->name . ': ' . $node->value; }, - NodeKind::DIRECTIVE => function (DirectiveNode $node) { + NodeKind::DIRECTIVE => function (DirectiveNode $node) : string { return '@' . $node->name . $this->wrap('(', $this->join($node->arguments, ', '), ')'); }, - NodeKind::NAMED_TYPE => static function (NamedTypeNode $node) { + NodeKind::NAMED_TYPE => static function (NamedTypeNode $node) : string { return $node->name; }, - NodeKind::LIST_TYPE => static function (ListTypeNode $node) { + NodeKind::LIST_TYPE => static function (ListTypeNode $node) : string { return '[' . $node->type . ']'; }, - NodeKind::NON_NULL_TYPE => static function (NonNullTypeNode $node) { + NodeKind::NON_NULL_TYPE => static function (NonNullTypeNode $node) : string { return $node->type . '!'; }, @@ -248,7 +248,7 @@ public function printAST($ast) ); }, - NodeKind::OPERATION_TYPE_DEFINITION => static function (OperationTypeDefinitionNode $def) { + NodeKind::OPERATION_TYPE_DEFINITION => static function (OperationTypeDefinitionNode $def) : string { return $def->operation . ': ' . $def->type; }, @@ -270,7 +270,7 @@ public function printAST($ast) }), NodeKind::FIELD_DEFINITION => $this->addDescription(function (FieldDefinitionNode $def) { - $noIndent = Utils::every($def->arguments, static function (string $arg) { + $noIndent = Utils::every($def->arguments, static function (string $arg) : bool { return strpos($arg, "\n") === false; }); @@ -437,7 +437,7 @@ function (InterfaceTypeDefinitionNode $def) { }, NodeKind::DIRECTIVE_DEFINITION => $this->addDescription(function (DirectiveDefinitionNode $def) { - $noIndent = Utils::every($def->arguments, static function (string $arg) { + $noIndent = Utils::every($def->arguments, static function (string $arg) : bool { return strpos($arg, "\n") === false; }); @@ -502,7 +502,7 @@ public function join($maybeArray, $separator = '') $separator, Utils::filter( $maybeArray, - static function ($x) { + static function ($x) : bool { return (bool) $x; } ) diff --git a/src/Server/Helper.php b/src/Server/Helper.php index 396589ae2..ce9bf1c5c 100644 --- a/src/Server/Helper.php +++ b/src/Server/Helper.php @@ -266,7 +266,7 @@ private function promiseToExecuteOperation( if (! empty($errors)) { $errors = Utils::map( $errors, - static function (RequestError $err) { + static function (RequestError $err) : Error { return Error::createLocatedError($err, null, null); } ); @@ -315,7 +315,7 @@ static function (RequestError $err) { ); } - $applyErrorHandling = static function (ExecutionResult $result) use ($config) { + $applyErrorHandling = static function (ExecutionResult $result) use ($config) : ExecutionResult { if ($config->getErrorsHandler()) { $result->setErrorsHandler($config->getErrorsHandler()); } @@ -434,7 +434,7 @@ private function resolveContextValue( public function sendResponse($result, $exitWhenDone = false) { if ($result instanceof Promise) { - $result->then(function ($actualResult) use ($exitWhenDone) { + $result->then(function ($actualResult) use ($exitWhenDone) : void { $this->doSendResponse($actualResult, $exitWhenDone); }); } else { @@ -482,7 +482,7 @@ private function resolveHttpStatus($result) if (is_array($result) && isset($result[0])) { Utils::each( $result, - static function ($executionResult, $index) { + static function ($executionResult, $index) : void { if (! $executionResult instanceof ExecutionResult) { throw new InvariantViolation(sprintf( 'Expecting every entry of batched query result to be instance of %s but entry at position %d is %s', diff --git a/src/Type/Definition/QueryPlan.php b/src/Type/Definition/QueryPlan.php index 03788232b..ace572fcb 100644 --- a/src/Type/Definition/QueryPlan.php +++ b/src/Type/Definition/QueryPlan.php @@ -79,7 +79,7 @@ public function getReferencedTypes() : array public function hasType(string $type) : bool { - return count(array_filter($this->getReferencedTypes(), static function (string $referencedType) use ($type) { + return count(array_filter($this->getReferencedTypes(), static function (string $referencedType) use ($type) : bool { return $type === $referencedType; })) > 0; } @@ -94,7 +94,7 @@ public function getReferencedFields() : array public function hasField(string $field) : bool { - return count(array_filter($this->getReferencedFields(), static function (string $referencedField) use ($field) { + return count(array_filter($this->getReferencedFields(), static function (string $referencedField) use ($field) : bool { return $field === $referencedField; })) > 0; } diff --git a/src/Type/Introspection.php b/src/Type/Introspection.php index 5bd928b31..fab7ecd0c 100644 --- a/src/Type/Introspection.php +++ b/src/Type/Introspection.php @@ -228,14 +228,14 @@ public static function _schema() 'types' => [ 'description' => 'A list of all types supported by this server.', 'type' => new NonNull(new ListOfType(new NonNull(self::_type()))), - 'resolve' => static function (Schema $schema) { + 'resolve' => static function (Schema $schema) : array { return array_values($schema->getTypeMap()); }, ], 'queryType' => [ 'description' => 'The type that query operations will be rooted at.', 'type' => new NonNull(self::_type()), - 'resolve' => static function (Schema $schema) { + 'resolve' => static function (Schema $schema) : ?ObjectType { return $schema->getQueryType(); }, ], @@ -244,7 +244,7 @@ public static function _schema() 'If this server supports mutation, the type that ' . 'mutation operations will be rooted at.', 'type' => self::_type(), - 'resolve' => static function (Schema $schema) { + 'resolve' => static function (Schema $schema) : ?ObjectType { return $schema->getMutationType(); }, ], @@ -336,7 +336,7 @@ public static function _type() if (empty($args['includeDeprecated'])) { $fields = array_filter( $fields, - static function (FieldDefinition $field) { + static function (FieldDefinition $field) : bool { return ! $field->deprecationReason; } ); @@ -350,7 +350,7 @@ static function (FieldDefinition $field) { ], 'interfaces' => [ 'type' => Type::listOf(Type::nonNull(self::_type())), - 'resolve' => static function ($type) { + 'resolve' => static function ($type) : ?array { if ($type instanceof ObjectType) { return $type->getInterfaces(); } @@ -360,7 +360,7 @@ static function (FieldDefinition $field) { ], 'possibleTypes' => [ 'type' => Type::listOf(Type::nonNull(self::_type())), - 'resolve' => static function ($type, $args, $context, ResolveInfo $info) { + 'resolve' => static function ($type, $args, $context, ResolveInfo $info) : ?array { if ($type instanceof InterfaceType || $type instanceof UnionType) { return $info->schema->getPossibleTypes($type); } @@ -380,7 +380,7 @@ static function (FieldDefinition $field) { if (empty($args['includeDeprecated'])) { $values = array_filter( $values, - static function ($value) { + static function ($value) : bool { return ! $value->deprecationReason; } ); @@ -394,7 +394,7 @@ static function ($value) { ], 'inputFields' => [ 'type' => Type::listOf(Type::nonNull(self::_inputValue())), - 'resolve' => static function ($type) { + 'resolve' => static function ($type) : ?array { if ($type instanceof InputObjectType) { return array_values($type->getFields()); } @@ -404,7 +404,7 @@ static function ($value) { ], 'ofType' => [ 'type' => self::_type(), - 'resolve' => static function ($type) { + 'resolve' => static function ($type) : ?Type { if ($type instanceof WrappingType) { return $type->getWrappedType(); } @@ -480,19 +480,19 @@ public static function _field() return [ 'name' => [ 'type' => Type::nonNull(Type::string()), - 'resolve' => static function (FieldDefinition $field) { + 'resolve' => static function (FieldDefinition $field) : string { return $field->name; }, ], 'description' => [ 'type' => Type::string(), - 'resolve' => static function (FieldDefinition $field) { + 'resolve' => static function (FieldDefinition $field) : ?string { return $field->description; }, ], 'args' => [ 'type' => Type::nonNull(Type::listOf(Type::nonNull(self::_inputValue()))), - 'resolve' => static function (FieldDefinition $field) { + 'resolve' => static function (FieldDefinition $field) : array { return empty($field->args) ? [] : $field->args; }, ], @@ -504,13 +504,13 @@ public static function _field() ], 'isDeprecated' => [ 'type' => Type::nonNull(Type::boolean()), - 'resolve' => static function (FieldDefinition $field) { + 'resolve' => static function (FieldDefinition $field) : bool { return (bool) $field->deprecationReason; }, ], 'deprecationReason' => [ 'type' => Type::string(), - 'resolve' => static function (FieldDefinition $field) { + 'resolve' => static function (FieldDefinition $field) : ?string { return $field->deprecationReason; }, ], @@ -536,7 +536,7 @@ public static function _inputValue() return [ 'name' => [ 'type' => Type::nonNull(Type::string()), - 'resolve' => static function ($inputValue) { + 'resolve' => static function ($inputValue) : string { /** @var FieldArgument|InputObjectField $inputValue */ $inputValue = $inputValue; @@ -545,7 +545,7 @@ public static function _inputValue() ], 'description' => [ 'type' => Type::string(), - 'resolve' => static function ($inputValue) { + 'resolve' => static function ($inputValue) : ?string { /** @var FieldArgument|InputObjectField $inputValue */ $inputValue = $inputValue; @@ -564,7 +564,7 @@ public static function _inputValue() 'type' => Type::string(), 'description' => 'A GraphQL-formatted string representing the default value for this input value.', - 'resolve' => static function ($inputValue) { + 'resolve' => static function ($inputValue) : ?string { /** @var FieldArgument|InputObjectField $inputValue */ $inputValue = $inputValue; @@ -609,7 +609,7 @@ public static function _enumValue() ], 'isDeprecated' => [ 'type' => Type::nonNull(Type::boolean()), - 'resolve' => static function ($enumValue) { + 'resolve' => static function ($enumValue) : bool { return (bool) $enumValue->deprecationReason; }, ], @@ -661,7 +661,7 @@ public static function _directive() ], 'args' => [ 'type' => Type::nonNull(Type::listOf(Type::nonNull(self::_inputValue()))), - 'resolve' => static function (Directive $directive) { + 'resolve' => static function (Directive $directive) : array { return $directive->args ?: []; }, ], @@ -779,7 +779,7 @@ public static function schemaMetaFieldDef() : FieldDefinition $args, $context, ResolveInfo $info - ) { + ) : Schema { return $info->schema; }, ]); @@ -798,7 +798,7 @@ public static function typeMetaFieldDef() : FieldDefinition 'args' => [ ['name' => 'name', 'type' => Type::nonNull(Type::string())], ], - 'resolve' => static function ($source, $args, $context, ResolveInfo $info) { + 'resolve' => static function ($source, $args, $context, ResolveInfo $info) : Type { return $info->schema->getType($args['name']); }, ]); @@ -820,7 +820,7 @@ public static function typeNameMetaFieldDef() : FieldDefinition $args, $context, ResolveInfo $info - ) { + ) : string { return $info->parentType->name; }, ]); diff --git a/src/Type/SchemaValidationContext.php b/src/Type/SchemaValidationContext.php index dcaee67d0..b37b0990d 100644 --- a/src/Type/SchemaValidationContext.php +++ b/src/Type/SchemaValidationContext.php @@ -5,6 +5,7 @@ namespace GraphQL\Type; use GraphQL\Error\Error; +use GraphQL\Language\AST\DirectiveDefinitionNode; use GraphQL\Language\AST\DirectiveNode; use GraphQL\Language\AST\EnumValueDefinitionNode; use GraphQL\Language\AST\FieldDefinitionNode; @@ -222,7 +223,7 @@ public function validateDirectiveDefinitions() $nodes = Utils::map( $directiveList, - static function (Directive $directive) { + static function (Directive $directive) : DirectiveDefinitionNode { return $directive->astNode; } ); @@ -263,7 +264,7 @@ static function ($directiveNode) { return Utils::filter( $subNodes, - static function ($argNode) use ($argName) { + static function ($argNode) use ($argName) : bool { return $argNode->name->value === $argName; } ); @@ -378,7 +379,7 @@ private function validateDirectivesAtLocation($directives, string $location) } $includes = Utils::some( $schemaDirective->locations, - static function ($schemaLocation) use ($location) { + static function ($schemaLocation) use ($location) : bool { return $schemaLocation === $location; } ); @@ -566,7 +567,7 @@ private function getAllFieldNodes($type, $fieldName) return $typeNode->fields; }); - return Utils::filter($subNodes, static function ($fieldNode) use ($fieldName) { + return Utils::filter($subNodes, static function ($fieldNode) use ($fieldName) : bool { return $fieldNode->name->value === $fieldName; }); } @@ -711,7 +712,7 @@ private function getAllImplementsInterfaceNodes(ObjectType $type, $iface) return $typeNode->interfaces; }); - return Utils::filter($subNodes, static function ($ifaceNode) use ($iface) { + return Utils::filter($subNodes, static function ($ifaceNode) use ($iface) : bool { return $ifaceNode->name->value === $iface->name; }); } @@ -911,7 +912,7 @@ private function getUnionMemberTypeNodes(UnionType $union, $typeName) return $unionNode->types; }); - return Utils::filter($subNodes, static function ($typeNode) use ($typeName) { + return Utils::filter($subNodes, static function ($typeNode) use ($typeName) : bool { return $typeNode->name->value === $typeName; }); } @@ -971,7 +972,7 @@ private function getEnumValueNodes(EnumType $enum, $valueName) return $enumNode->values; }); - return Utils::filter($subNodes, static function ($valueNode) use ($valueName) { + return Utils::filter($subNodes, static function ($valueNode) use ($valueName) : bool { return $valueNode->name->value === $valueName; }); } diff --git a/src/Utils/ASTDefinitionBuilder.php b/src/Utils/ASTDefinitionBuilder.php index d9902b1f2..c032442ed 100644 --- a/src/Utils/ASTDefinitionBuilder.php +++ b/src/Utils/ASTDefinitionBuilder.php @@ -336,7 +336,7 @@ private function makeImplementedInterfaces(ObjectTypeDefinitionNode $def) // validation with validateSchema() will produce more actionable results. return Utils::map( $def->interfaces, - function ($iface) { + function ($iface) : Type { return $this->buildType($iface); } ); @@ -370,7 +370,7 @@ private function makeEnumDef(EnumTypeDefinitionNode $def) static function ($enumValue) { return $enumValue->name->value; }, - function ($enumValue) { + function ($enumValue) : array { return [ 'description' => $this->getDescription($enumValue), 'deprecationReason' => $this->getDeprecationReason($enumValue), @@ -395,7 +395,7 @@ private function makeUnionDef(UnionTypeDefinitionNode $def) ? function () use ($def) { return Utils::map( $def->types, - function ($typeNode) { + function ($typeNode) : Type { return $this->buildType($typeNode); } ); diff --git a/src/Utils/BreakingChangesFinder.php b/src/Utils/BreakingChangesFinder.php index 733ca1889..8ef9253d2 100644 --- a/src/Utils/BreakingChangesFinder.php +++ b/src/Utils/BreakingChangesFinder.php @@ -504,7 +504,7 @@ public static function findArgChanges( $newArgs = $newTypeFields[$fieldName]->args; $newArgDef = Utils::find( $newArgs, - static function ($arg) use ($oldArgDef) { + static function ($arg) use ($oldArgDef) : bool { return $arg->name === $oldArgDef->name; } ); @@ -544,7 +544,7 @@ static function ($arg) use ($oldArgDef) { $oldArgs = $oldTypeFields[$fieldName]->args; $oldArgDef = Utils::find( $oldArgs, - static function ($arg) use ($newTypeFieldArgDef) { + static function ($arg) use ($newTypeFieldArgDef) : bool { return $arg->name === $newTypeFieldArgDef->name; } ); diff --git a/src/Utils/BuildSchema.php b/src/Utils/BuildSchema.php index 57e9c16f4..fb52b1110 100644 --- a/src/Utils/BuildSchema.php +++ b/src/Utils/BuildSchema.php @@ -18,6 +18,7 @@ use GraphQL\Language\Parser; use GraphQL\Language\Source; use GraphQL\Type\Definition\Directive; +use GraphQL\Type\Definition\Type; use GraphQL\Type\Schema; use GraphQL\Validator\DocumentValidator; use function array_map; @@ -145,7 +146,7 @@ public function buildSchema() $DefinitionBuilder = new ASTDefinitionBuilder( $this->nodeMap, $this->options, - static function ($typeName) { + static function ($typeName) : void { throw new Error('Type "' . $typeName . '" not found in document.'); }, $this->typeConfigDecorator @@ -189,12 +190,12 @@ static function (Directive $directive) : string { 'subscription' => isset($operationTypes['subscription']) ? $DefinitionBuilder->buildType($operationTypes['subscription']) : null, - 'typeLoader' => static function ($name) use ($DefinitionBuilder) { + 'typeLoader' => static function ($name) use ($DefinitionBuilder) : Type { return $DefinitionBuilder->buildType($name); }, 'directives' => $directives, 'astNode' => $schemaDef, - 'types' => function () use ($DefinitionBuilder) { + 'types' => function () use ($DefinitionBuilder) : array { $types = []; /** @var ScalarTypeDefinitionNode|ObjectTypeDefinitionNode|InterfaceTypeDefinitionNode|UnionTypeDefinitionNode|EnumTypeDefinitionNode|InputObjectTypeDefinitionNode $def */ foreach ($this->nodeMap as $name => $def) { diff --git a/src/Utils/SchemaExtender.php b/src/Utils/SchemaExtender.php index 3249738d2..e24639ba2 100644 --- a/src/Utils/SchemaExtender.php +++ b/src/Utils/SchemaExtender.php @@ -141,7 +141,7 @@ protected static function extendUnionType(UnionType $type) : UnionType return new UnionType([ 'name' => $type->name, 'description' => $type->description, - 'types' => static function () use ($type) { + 'types' => static function () use ($type) : array { return static::extendPossibleTypes($type); }, 'astNode' => $type->astNode, @@ -166,7 +166,7 @@ protected static function extendInputObjectType(InputObjectType $type) : InputOb return new InputObjectType([ 'name' => $type->name, 'description' => $type->description, - 'fields' => static function () use ($type) { + 'fields' => static function () use ($type) : array { return static::extendInputFieldMap($type); }, 'astNode' => $type->astNode, @@ -315,7 +315,7 @@ protected static function extendArgs(array $args) : array { return Utils::keyValMap( $args, - static function (FieldArgument $arg) { + static function (FieldArgument $arg) : string { return $arg->name; }, static function (FieldArgument $arg) { @@ -382,10 +382,10 @@ protected static function extendObjectType(ObjectType $type) : ObjectType return new ObjectType([ 'name' => $type->name, 'description' => $type->description, - 'interfaces' => static function () use ($type) { + 'interfaces' => static function () use ($type) : array { return static::extendImplementedInterfaces($type); }, - 'fields' => static function () use ($type) { + 'fields' => static function () use ($type) : array { return static::extendFieldMap($type); }, 'astNode' => $type->astNode, @@ -400,7 +400,7 @@ protected static function extendInterfaceType(InterfaceType $type) : InterfaceTy return new InterfaceType([ 'name' => $type->name, 'description' => $type->description, - 'fields' => static function () use ($type) { + 'fields' => static function () use ($type) : array { return static::extendFieldMap($type); }, 'astNode' => $type->astNode, @@ -466,7 +466,7 @@ protected static function extendMaybeNamedType(?NamedType $type = null) */ protected static function getMergedDirectives(Schema $schema, array $directiveDefinitions) : array { - $existingDirectives = array_map(static function (Directive $directive) { + $existingDirectives = array_map(static function (Directive $directive) : Directive { return static::extendDirective($directive); }, $schema->getDirectives()); @@ -619,7 +619,7 @@ static function (string $typeName) use ($schema) { return static::extendNamedType($type); }, array_values($schema->getTypeMap())), // Do the same with new types. - array_map(static function ($type) { + array_map(static function ($type) : Type { return static::$astBuilder->buildType($type); }, array_values($typeDefinitionMap)) ); diff --git a/src/Utils/SchemaPrinter.php b/src/Utils/SchemaPrinter.php index ccbb00734..795c4cc2d 100644 --- a/src/Utils/SchemaPrinter.php +++ b/src/Utils/SchemaPrinter.php @@ -51,10 +51,10 @@ public static function doPrint(Schema $schema, array $options = []) : string { return self::printFilteredSchema( $schema, - static function ($type) { + static function ($type) : bool { return ! Directive::isSpecifiedDirective($type); }, - static function ($type) { + static function ($type) : bool { return ! Type::isBuiltInType($type); }, $options @@ -85,13 +85,13 @@ static function ($directive) use ($directiveFilter) { array_merge( [self::printSchemaDefinition($schema)], array_map( - static function ($directive) use ($options) { + static function ($directive) use ($options) : string { return self::printDirective($directive, $options); }, $directives ), array_map( - static function ($type) use ($options) { + static function ($type) use ($options) : string { return self::printType($type, $options); }, $types @@ -273,7 +273,7 @@ private static function printArgs($options, $args, $indentation = '') : string // If every arg does not have a description, print them on one line. if (Utils::every( $args, - static function ($arg) { + static function ($arg) : bool { return empty($arg->description); } )) { @@ -285,7 +285,7 @@ static function ($arg) { implode( "\n", array_map( - static function ($arg, $i) use ($indentation, $options) { + static function ($arg, $i) use ($indentation, $options) : string { return self::printDescription($options, $arg, ' ' . $indentation, ! $i) . ' ' . $indentation . self::printInputValue($arg); }, @@ -357,7 +357,7 @@ private static function printObject(ObjectType $type, array $options) : string ? ' implements ' . implode( ' & ', array_map( - static function ($i) { + static function ($i) : string { return $i->name; }, $interfaces @@ -379,7 +379,7 @@ private static function printFields($options, $type) : string return implode( "\n", array_map( - static function ($f, $i) use ($options) { + static function ($f, $i) use ($options) : string { return self::printDescription($options, $f, ' ', ! $i) . ' ' . $f->name . self::printArgs($options, $f->args, ' ') . ': ' . (string) $f->getType() . self::printDeprecated($f); @@ -439,7 +439,7 @@ private static function printEnumValues($values, $options) : string return implode( "\n", array_map( - static function ($value, $i) use ($options) { + static function ($value, $i) use ($options) : string { return self::printDescription($options, $value, ' ', ! $i) . ' ' . $value->name . self::printDeprecated($value); }, @@ -463,7 +463,7 @@ private static function printInputObject(InputObjectType $type, array $options) implode( "\n", array_map( - static function ($f, $i) use ($options) { + static function ($f, $i) use ($options) : string { return self::printDescription($options, $f, ' ', ! $i) . ' ' . self::printInputValue($f); }, $fields, diff --git a/src/Utils/TypeInfo.php b/src/Utils/TypeInfo.php index 1468847f9..870180115 100644 --- a/src/Utils/TypeInfo.php +++ b/src/Utils/TypeInfo.php @@ -323,7 +323,7 @@ public function enter(Node $node) /** @var FieldArgument $argDef */ $argDef = Utils::find( $fieldOrDirective->args, - static function ($arg) use ($node) { + static function ($arg) use ($node) : bool { return $arg->name === $node->name->value; } ); diff --git a/src/Utils/Utils.php b/src/Utils/Utils.php index 9f0defa55..7919f262e 100644 --- a/src/Utils/Utils.php +++ b/src/Utils/Utils.php @@ -560,7 +560,7 @@ public static function withErrorHandling(callable $fn, array &$errors) { return static function () use ($fn, &$errors) { // Catch custom errors (to report them in query results) - set_error_handler(static function ($severity, $message, $file, $line) use (&$errors) { + set_error_handler(static function ($severity, $message, $file, $line) use (&$errors) : void { $errors[] = new ErrorException($message, 0, $severity, $file, $line); }); @@ -580,7 +580,7 @@ public static function withErrorHandling(callable $fn, array &$errors) public static function quotedOrList(array $items) { $items = array_map( - static function ($item) { + static function ($item) : string { return sprintf('"%s"', $item); }, $items @@ -609,7 +609,7 @@ public static function orList(array $items) return array_reduce( range(1, $selectedLength - 1), - static function ($list, $index) use ($selected, $selectedLength) { + static function ($list, $index) use ($selected, $selectedLength) : string { return $list . ($selectedLength > 2 ? ', ' : ' ') . ($index === $selectedLength - 1 ? 'or ' : '') . diff --git a/src/Utils/Value.php b/src/Utils/Value.php index 595172a25..2920883a6 100644 --- a/src/Utils/Value.php +++ b/src/Utils/Value.php @@ -90,7 +90,7 @@ public static function coerceValue($value, InputType $type, $blameNode = null, ? $suggestions = Utils::suggestionList( Utils::printSafe($value), array_map( - static function ($enumValue) { + static function ($enumValue) : string { return $enumValue->name; }, $type->getValues() diff --git a/src/Validator/DocumentValidator.php b/src/Validator/DocumentValidator.php index 7df559621..0b5fb0c1b 100644 --- a/src/Validator/DocumentValidator.php +++ b/src/Validator/DocumentValidator.php @@ -264,7 +264,7 @@ public static function isError($value) return is_array($value) ? count(array_filter( $value, - static function ($item) { + static function ($item) : bool { return $item instanceof Throwable; } )) === count($value) diff --git a/src/Validator/Rules/ExecutableDefinitions.php b/src/Validator/Rules/ExecutableDefinitions.php index 632953e8a..3d1887daf 100644 --- a/src/Validator/Rules/ExecutableDefinitions.php +++ b/src/Validator/Rules/ExecutableDefinitions.php @@ -11,6 +11,7 @@ use GraphQL\Language\AST\OperationDefinitionNode; use GraphQL\Language\AST\TypeSystemDefinitionNode; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Validator\ValidationContext; use function sprintf; @@ -25,7 +26,7 @@ class ExecutableDefinitions extends ValidationRule public function getVisitor(ValidationContext $context) { return [ - NodeKind::DOCUMENT => static function (DocumentNode $node) use ($context) { + NodeKind::DOCUMENT => static function (DocumentNode $node) use ($context) : VisitorOperation { /** @var FragmentDefinitionNode|OperationDefinitionNode|TypeSystemDefinitionNode $definition */ foreach ($node->definitions as $definition) { if ($definition instanceof OperationDefinitionNode || diff --git a/src/Validator/Rules/FieldsOnCorrectType.php b/src/Validator/Rules/FieldsOnCorrectType.php index 105325536..55b66eeb6 100644 --- a/src/Validator/Rules/FieldsOnCorrectType.php +++ b/src/Validator/Rules/FieldsOnCorrectType.php @@ -23,7 +23,7 @@ class FieldsOnCorrectType extends ValidationRule public function getVisitor(ValidationContext $context) { return [ - NodeKind::FIELD => function (FieldNode $node) use ($context) { + NodeKind::FIELD => function (FieldNode $node) use ($context) : void { $type = $context->getParentType(); if (! $type) { return; diff --git a/src/Validator/Rules/FragmentsOnCompositeTypes.php b/src/Validator/Rules/FragmentsOnCompositeTypes.php index c5ca80771..db72a057b 100644 --- a/src/Validator/Rules/FragmentsOnCompositeTypes.php +++ b/src/Validator/Rules/FragmentsOnCompositeTypes.php @@ -19,7 +19,7 @@ class FragmentsOnCompositeTypes extends ValidationRule public function getVisitor(ValidationContext $context) { return [ - NodeKind::INLINE_FRAGMENT => static function (InlineFragmentNode $node) use ($context) { + NodeKind::INLINE_FRAGMENT => static function (InlineFragmentNode $node) use ($context) : void { if (! $node->typeCondition) { return; } @@ -34,7 +34,7 @@ public function getVisitor(ValidationContext $context) [$node->typeCondition] )); }, - NodeKind::FRAGMENT_DEFINITION => static function (FragmentDefinitionNode $node) use ($context) { + NodeKind::FRAGMENT_DEFINITION => static function (FragmentDefinitionNode $node) use ($context) : void { $type = TypeInfo::typeFromAST($context->getSchema(), $node->typeCondition); if (! $type || Type::isCompositeType($type)) { diff --git a/src/Validator/Rules/KnownArgumentNames.php b/src/Validator/Rules/KnownArgumentNames.php index 0a4945ebd..685f4176f 100644 --- a/src/Validator/Rules/KnownArgumentNames.php +++ b/src/Validator/Rules/KnownArgumentNames.php @@ -48,7 +48,7 @@ public function getVisitor(ValidationContext $context) Utils::suggestionList( $node->name->value, array_map( - static function ($arg) { + static function ($arg) : string { return $arg->name; }, $fieldDef->args diff --git a/src/Validator/Rules/KnownArgumentNamesOnDirectives.php b/src/Validator/Rules/KnownArgumentNamesOnDirectives.php index 4087a321a..e636482c6 100644 --- a/src/Validator/Rules/KnownArgumentNamesOnDirectives.php +++ b/src/Validator/Rules/KnownArgumentNamesOnDirectives.php @@ -68,7 +68,7 @@ static function (FieldArgument $arg) : string { } return [ - NodeKind::DIRECTIVE => static function (DirectiveNode $directiveNode) use ($directiveArgs, $context) { + NodeKind::DIRECTIVE => static function (DirectiveNode $directiveNode) use ($directiveArgs, $context) : void { $directiveName = $directiveNode->name->value; $knownArgs = $directiveArgs[$directiveName] ?? null; diff --git a/src/Validator/Rules/KnownFragmentNames.php b/src/Validator/Rules/KnownFragmentNames.php index e26e233e0..052686f28 100644 --- a/src/Validator/Rules/KnownFragmentNames.php +++ b/src/Validator/Rules/KnownFragmentNames.php @@ -15,7 +15,7 @@ class KnownFragmentNames extends ValidationRule public function getVisitor(ValidationContext $context) { return [ - NodeKind::FRAGMENT_SPREAD => static function (FragmentSpreadNode $node) use ($context) { + NodeKind::FRAGMENT_SPREAD => static function (FragmentSpreadNode $node) use ($context) : void { $fragmentName = $node->name->value; $fragment = $context->getFragment($fragmentName); if ($fragment) { diff --git a/src/Validator/Rules/KnownTypeNames.php b/src/Validator/Rules/KnownTypeNames.php index 9abaf0aeb..6f38e237d 100644 --- a/src/Validator/Rules/KnownTypeNames.php +++ b/src/Validator/Rules/KnownTypeNames.php @@ -8,6 +8,7 @@ use GraphQL\Language\AST\NamedTypeNode; use GraphQL\Language\AST\NodeKind; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Utils\Utils; use GraphQL\Validator\ValidationContext; use function array_keys; @@ -23,7 +24,7 @@ class KnownTypeNames extends ValidationRule { public function getVisitor(ValidationContext $context) { - $skip = static function () { + $skip = static function () : VisitorOperation { return Visitor::skipNode(); }; @@ -35,7 +36,7 @@ public function getVisitor(ValidationContext $context) NodeKind::INTERFACE_TYPE_DEFINITION => $skip, NodeKind::UNION_TYPE_DEFINITION => $skip, NodeKind::INPUT_OBJECT_TYPE_DEFINITION => $skip, - NodeKind::NAMED_TYPE => static function (NamedTypeNode $node) use ($context) { + NodeKind::NAMED_TYPE => static function (NamedTypeNode $node) use ($context) : void { $schema = $context->getSchema(); $typeName = $node->name->value; $type = $schema->getType($typeName); diff --git a/src/Validator/Rules/LoneAnonymousOperation.php b/src/Validator/Rules/LoneAnonymousOperation.php index ebfba6299..f0a68cf6e 100644 --- a/src/Validator/Rules/LoneAnonymousOperation.php +++ b/src/Validator/Rules/LoneAnonymousOperation.php @@ -26,10 +26,10 @@ public function getVisitor(ValidationContext $context) $operationCount = 0; return [ - NodeKind::DOCUMENT => static function (DocumentNode $node) use (&$operationCount) { + NodeKind::DOCUMENT => static function (DocumentNode $node) use (&$operationCount) : void { $tmp = Utils::filter( $node->definitions, - static function (Node $definition) { + static function (Node $definition) : bool { return $definition instanceof OperationDefinitionNode; } ); diff --git a/src/Validator/Rules/LoneSchemaDefinition.php b/src/Validator/Rules/LoneSchemaDefinition.php index bd89f8c46..4ece976b6 100644 --- a/src/Validator/Rules/LoneSchemaDefinition.php +++ b/src/Validator/Rules/LoneSchemaDefinition.php @@ -41,7 +41,7 @@ public function getSDLVisitor(SDLValidationContext $context) $schemaDefinitionsCount = 0; return [ - NodeKind::SCHEMA_DEFINITION => static function (SchemaDefinitionNode $node) use ($alreadyDefined, $context, &$schemaDefinitionsCount) { + NodeKind::SCHEMA_DEFINITION => static function (SchemaDefinitionNode $node) use ($alreadyDefined, $context, &$schemaDefinitionsCount) : void { if ($alreadyDefined !== false) { $context->reportError(new Error(self::canNotDefineSchemaWithinExtensionMessage(), $node)); diff --git a/src/Validator/Rules/NoFragmentCycles.php b/src/Validator/Rules/NoFragmentCycles.php index e01b7631d..a7f938018 100644 --- a/src/Validator/Rules/NoFragmentCycles.php +++ b/src/Validator/Rules/NoFragmentCycles.php @@ -9,6 +9,7 @@ use GraphQL\Language\AST\FragmentSpreadNode; use GraphQL\Language\AST\NodeKind; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Utils\Utils; use GraphQL\Validator\ValidationContext; use function array_pop; @@ -41,10 +42,10 @@ public function getVisitor(ValidationContext $context) $this->spreadPathIndexByName = []; return [ - NodeKind::OPERATION_DEFINITION => static function () { + NodeKind::OPERATION_DEFINITION => static function () : VisitorOperation { return Visitor::skipNode(); }, - NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) use ($context) { + NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) use ($context) : VisitorOperation { $this->detectCycleRecursive($node, $context); return Visitor::skipNode(); diff --git a/src/Validator/Rules/NoUndefinedVariables.php b/src/Validator/Rules/NoUndefinedVariables.php index f59d03f6a..5dbba94a6 100644 --- a/src/Validator/Rules/NoUndefinedVariables.php +++ b/src/Validator/Rules/NoUndefinedVariables.php @@ -23,10 +23,10 @@ public function getVisitor(ValidationContext $context) return [ NodeKind::OPERATION_DEFINITION => [ - 'enter' => static function () use (&$variableNameDefined) { + 'enter' => static function () use (&$variableNameDefined) : void { $variableNameDefined = []; }, - 'leave' => static function (OperationDefinitionNode $operation) use (&$variableNameDefined, $context) { + 'leave' => static function (OperationDefinitionNode $operation) use (&$variableNameDefined, $context) : void { $usages = $context->getRecursiveVariableUsages($operation); foreach ($usages as $usage) { @@ -49,7 +49,7 @@ public function getVisitor(ValidationContext $context) } }, ], - NodeKind::VARIABLE_DEFINITION => static function (VariableDefinitionNode $def) use (&$variableNameDefined) { + NodeKind::VARIABLE_DEFINITION => static function (VariableDefinitionNode $def) use (&$variableNameDefined) : void { $variableNameDefined[$def->variable->name->value] = true; }, ]; diff --git a/src/Validator/Rules/NoUnusedFragments.php b/src/Validator/Rules/NoUnusedFragments.php index d1cd3668f..6c3f19823 100644 --- a/src/Validator/Rules/NoUnusedFragments.php +++ b/src/Validator/Rules/NoUnusedFragments.php @@ -9,6 +9,7 @@ use GraphQL\Language\AST\NodeKind; use GraphQL\Language\AST\OperationDefinitionNode; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Validator\ValidationContext; use function sprintf; @@ -26,18 +27,18 @@ public function getVisitor(ValidationContext $context) $this->fragmentDefs = []; return [ - NodeKind::OPERATION_DEFINITION => function ($node) { + NodeKind::OPERATION_DEFINITION => function ($node) : VisitorOperation { $this->operationDefs[] = $node; return Visitor::skipNode(); }, - NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $def) { + NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $def) : VisitorOperation { $this->fragmentDefs[] = $def; return Visitor::skipNode(); }, NodeKind::DOCUMENT => [ - 'leave' => function () use ($context) { + 'leave' => function () use ($context) : void { $fragmentNameUsed = []; foreach ($this->operationDefs as $operation) { diff --git a/src/Validator/Rules/NoUnusedVariables.php b/src/Validator/Rules/NoUnusedVariables.php index d6a4486d7..592279cd3 100644 --- a/src/Validator/Rules/NoUnusedVariables.php +++ b/src/Validator/Rules/NoUnusedVariables.php @@ -22,10 +22,10 @@ public function getVisitor(ValidationContext $context) return [ NodeKind::OPERATION_DEFINITION => [ - 'enter' => function () { + 'enter' => function () : void { $this->variableDefs = []; }, - 'leave' => function (OperationDefinitionNode $operation) use ($context) { + 'leave' => function (OperationDefinitionNode $operation) use ($context) : void { $variableNameUsed = []; $usages = $context->getRecursiveVariableUsages($operation); $opName = $operation->name !== null @@ -51,7 +51,7 @@ public function getVisitor(ValidationContext $context) } }, ], - NodeKind::VARIABLE_DEFINITION => function ($def) { + NodeKind::VARIABLE_DEFINITION => function ($def) : void { $this->variableDefs[] = $def; }, ]; diff --git a/src/Validator/Rules/OverlappingFieldsCanBeMerged.php b/src/Validator/Rules/OverlappingFieldsCanBeMerged.php index 350318867..790c28cf9 100644 --- a/src/Validator/Rules/OverlappingFieldsCanBeMerged.php +++ b/src/Validator/Rules/OverlappingFieldsCanBeMerged.php @@ -59,7 +59,7 @@ public function getVisitor(ValidationContext $context) $this->cachedFieldsAndFragmentNames = new SplObjectStorage(); return [ - NodeKind::SELECTION_SET => function (SelectionSetNode $selectionSet) use ($context) { + NodeKind::SELECTION_SET => function (SelectionSetNode $selectionSet) use ($context) : void { $conflicts = $this->findConflictsWithinSelectionSet( $context, $context->getParentType(), @@ -845,14 +845,14 @@ static function ($conflict) { ], array_reduce( $conflicts, - static function ($allFields, $conflict) { + static function ($allFields, $conflict) : array { return array_merge($allFields, $conflict[1]); }, [$ast1] ), array_reduce( $conflicts, - static function ($allFields, $conflict) { + static function ($allFields, $conflict) : array { return array_merge($allFields, $conflict[2]); }, [$ast2] @@ -879,7 +879,7 @@ public static function reasonMessage($reason) { if (is_array($reason)) { $tmp = array_map( - static function ($tmp) { + static function ($tmp) : string { [$responseName, $subReason] = $tmp; $reasonMessage = self::reasonMessage($subReason); diff --git a/src/Validator/Rules/PossibleFragmentSpreads.php b/src/Validator/Rules/PossibleFragmentSpreads.php index 26611e6da..184f58bec 100644 --- a/src/Validator/Rules/PossibleFragmentSpreads.php +++ b/src/Validator/Rules/PossibleFragmentSpreads.php @@ -23,7 +23,7 @@ class PossibleFragmentSpreads extends ValidationRule public function getVisitor(ValidationContext $context) { return [ - NodeKind::INLINE_FRAGMENT => function (InlineFragmentNode $node) use ($context) { + NodeKind::INLINE_FRAGMENT => function (InlineFragmentNode $node) use ($context) : void { $fragType = $context->getType(); $parentType = $context->getParentType(); @@ -38,7 +38,7 @@ public function getVisitor(ValidationContext $context) [$node] )); }, - NodeKind::FRAGMENT_SPREAD => function (FragmentSpreadNode $node) use ($context) { + NodeKind::FRAGMENT_SPREAD => function (FragmentSpreadNode $node) use ($context) : void { $fragName = $node->name->value; $fragType = $this->getFragmentType($context, $fragName); $parentType = $context->getParentType(); diff --git a/src/Validator/Rules/ProvidedRequiredArguments.php b/src/Validator/Rules/ProvidedRequiredArguments.php index 2099f3c48..41730ebe2 100644 --- a/src/Validator/Rules/ProvidedRequiredArguments.php +++ b/src/Validator/Rules/ProvidedRequiredArguments.php @@ -9,6 +9,7 @@ use GraphQL\Language\AST\FieldNode; use GraphQL\Language\AST\NodeKind; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Type\Definition\NonNull; use GraphQL\Validator\ValidationContext; use function sprintf; @@ -19,7 +20,7 @@ public function getVisitor(ValidationContext $context) { return [ NodeKind::FIELD => [ - 'leave' => static function (FieldNode $fieldNode) use ($context) { + 'leave' => static function (FieldNode $fieldNode) use ($context) : ?VisitorOperation { $fieldDef = $context->getFieldDef(); if (! $fieldDef) { @@ -42,10 +43,12 @@ public function getVisitor(ValidationContext $context) [$fieldNode] )); } + + return null; }, ], NodeKind::DIRECTIVE => [ - 'leave' => static function (DirectiveNode $directiveNode) use ($context) { + 'leave' => static function (DirectiveNode $directiveNode) use ($context) : ?VisitorOperation { $directiveDef = $context->getDirective(); if (! $directiveDef) { return Visitor::skipNode(); @@ -71,6 +74,8 @@ public function getVisitor(ValidationContext $context) [$directiveNode] )); } + + return null; }, ], ]; diff --git a/src/Validator/Rules/ProvidedRequiredArgumentsOnDirectives.php b/src/Validator/Rules/ProvidedRequiredArgumentsOnDirectives.php index c26c061c6..2eacdc202 100644 --- a/src/Validator/Rules/ProvidedRequiredArgumentsOnDirectives.php +++ b/src/Validator/Rules/ProvidedRequiredArgumentsOnDirectives.php @@ -85,7 +85,7 @@ static function (NamedTypeNode $argument) : string { } return [ - NodeKind::DIRECTIVE => static function (DirectiveNode $directiveNode) use ($requiredArgsMap, $context) { + NodeKind::DIRECTIVE => static function (DirectiveNode $directiveNode) use ($requiredArgsMap, $context) : ?string { $directiveName = $directiveNode->name->value; $requiredArgs = $requiredArgsMap[$directiveName] ?? null; if (! $requiredArgs) { @@ -109,6 +109,8 @@ static function (ArgumentNode $arg) : string { new Error(static::missingDirectiveArgMessage($directiveName, $argName), [$directiveNode]) ); } + + return null; }, ]; } diff --git a/src/Validator/Rules/QueryComplexity.php b/src/Validator/Rules/QueryComplexity.php index 7d98c2e25..b084799b3 100644 --- a/src/Validator/Rules/QueryComplexity.php +++ b/src/Validator/Rules/QueryComplexity.php @@ -15,6 +15,7 @@ use GraphQL\Language\AST\OperationDefinitionNode; use GraphQL\Language\AST\SelectionSetNode; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Type\Definition\Directive; use GraphQL\Type\Definition\FieldDefinition; use GraphQL\Validator\ValidationContext; @@ -60,7 +61,7 @@ public function getVisitor(ValidationContext $context) return $this->invokeIfNeeded( $context, [ - NodeKind::SELECTION_SET => function (SelectionSetNode $selectionSet) use ($context) { + NodeKind::SELECTION_SET => function (SelectionSetNode $selectionSet) use ($context) : void { $this->fieldNodeAndDefs = $this->collectFieldASTsAndDefs( $context, $context->getParentType(), @@ -69,13 +70,13 @@ public function getVisitor(ValidationContext $context) $this->fieldNodeAndDefs ); }, - NodeKind::VARIABLE_DEFINITION => function ($def) { + NodeKind::VARIABLE_DEFINITION => function ($def) : VisitorOperation { $this->variableDefs[] = $def; return Visitor::skipNode(); }, NodeKind::OPERATION_DEFINITION => [ - 'leave' => function (OperationDefinitionNode $operationDefinition) use ($context, &$complexity) { + 'leave' => function (OperationDefinitionNode $operationDefinition) use ($context, &$complexity) : void { $errors = $context->getErrors(); if (! empty($errors)) { diff --git a/src/Validator/Rules/QueryDepth.php b/src/Validator/Rules/QueryDepth.php index cb01dd235..9b83d061e 100644 --- a/src/Validator/Rules/QueryDepth.php +++ b/src/Validator/Rules/QueryDepth.php @@ -31,7 +31,7 @@ public function getVisitor(ValidationContext $context) $context, [ NodeKind::OPERATION_DEFINITION => [ - 'leave' => function (OperationDefinitionNode $operationDefinition) use ($context) { + 'leave' => function (OperationDefinitionNode $operationDefinition) use ($context) : void { $maxDepth = $this->fieldDepth($operationDefinition); if ($maxDepth <= $this->getMaxQueryDepth()) { diff --git a/src/Validator/Rules/ScalarLeafs.php b/src/Validator/Rules/ScalarLeafs.php index 1bd25152b..f1714239e 100644 --- a/src/Validator/Rules/ScalarLeafs.php +++ b/src/Validator/Rules/ScalarLeafs.php @@ -16,7 +16,7 @@ class ScalarLeafs extends ValidationRule public function getVisitor(ValidationContext $context) { return [ - NodeKind::FIELD => static function (FieldNode $node) use ($context) { + NodeKind::FIELD => static function (FieldNode $node) use ($context) : void { $type = $context->getType(); if (! $type) { return; diff --git a/src/Validator/Rules/UniqueArgumentNames.php b/src/Validator/Rules/UniqueArgumentNames.php index 982fd6346..f3010bc77 100644 --- a/src/Validator/Rules/UniqueArgumentNames.php +++ b/src/Validator/Rules/UniqueArgumentNames.php @@ -9,6 +9,7 @@ use GraphQL\Language\AST\NameNode; use GraphQL\Language\AST\NodeKind; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Validator\ASTValidationContext; use GraphQL\Validator\SDLValidationContext; use GraphQL\Validator\ValidationContext; @@ -34,13 +35,13 @@ public function getASTVisitor(ASTValidationContext $context) $this->knownArgNames = []; return [ - NodeKind::FIELD => function () { + NodeKind::FIELD => function () : void { $this->knownArgNames = []; }, - NodeKind::DIRECTIVE => function () { + NodeKind::DIRECTIVE => function () : void { $this->knownArgNames = []; }, - NodeKind::ARGUMENT => function (ArgumentNode $node) use ($context) { + NodeKind::ARGUMENT => function (ArgumentNode $node) use ($context) : VisitorOperation { $argName = $node->name->value; if (! empty($this->knownArgNames[$argName])) { $context->reportError(new Error( diff --git a/src/Validator/Rules/UniqueDirectivesPerLocation.php b/src/Validator/Rules/UniqueDirectivesPerLocation.php index 9b784f19c..6860222d5 100644 --- a/src/Validator/Rules/UniqueDirectivesPerLocation.php +++ b/src/Validator/Rules/UniqueDirectivesPerLocation.php @@ -27,7 +27,7 @@ public function getSDLVisitor(SDLValidationContext $context) public function getASTVisitor(ASTValidationContext $context) { return [ - 'enter' => static function (Node $node) use ($context) { + 'enter' => static function (Node $node) use ($context) : void { if (! isset($node->directives)) { return; } diff --git a/src/Validator/Rules/UniqueFragmentNames.php b/src/Validator/Rules/UniqueFragmentNames.php index 475e6b3fa..6333a10c2 100644 --- a/src/Validator/Rules/UniqueFragmentNames.php +++ b/src/Validator/Rules/UniqueFragmentNames.php @@ -9,6 +9,7 @@ use GraphQL\Language\AST\NameNode; use GraphQL\Language\AST\NodeKind; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Validator\ValidationContext; use function sprintf; @@ -22,10 +23,10 @@ public function getVisitor(ValidationContext $context) $this->knownFragmentNames = []; return [ - NodeKind::OPERATION_DEFINITION => static function () { + NodeKind::OPERATION_DEFINITION => static function () : VisitorOperation { return Visitor::skipNode(); }, - NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) use ($context) { + NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) use ($context) : VisitorOperation { $fragmentName = $node->name->value; if (empty($this->knownFragmentNames[$fragmentName])) { $this->knownFragmentNames[$fragmentName] = $node->name; diff --git a/src/Validator/Rules/UniqueInputFieldNames.php b/src/Validator/Rules/UniqueInputFieldNames.php index da36b9bf8..5eab0260d 100644 --- a/src/Validator/Rules/UniqueInputFieldNames.php +++ b/src/Validator/Rules/UniqueInputFieldNames.php @@ -9,6 +9,7 @@ use GraphQL\Language\AST\NodeKind; use GraphQL\Language\AST\ObjectFieldNode; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Validator\ASTValidationContext; use GraphQL\Validator\SDLValidationContext; use GraphQL\Validator\ValidationContext; @@ -40,15 +41,15 @@ public function getASTVisitor(ASTValidationContext $context) return [ NodeKind::OBJECT => [ - 'enter' => function () { + 'enter' => function () : void { $this->knownNameStack[] = $this->knownNames; $this->knownNames = []; }, - 'leave' => function () { + 'leave' => function () : void { $this->knownNames = array_pop($this->knownNameStack); }, ], - NodeKind::OBJECT_FIELD => function (ObjectFieldNode $node) use ($context) { + NodeKind::OBJECT_FIELD => function (ObjectFieldNode $node) use ($context) : VisitorOperation { $fieldName = $node->name->value; if (! empty($this->knownNames[$fieldName])) { diff --git a/src/Validator/Rules/UniqueOperationNames.php b/src/Validator/Rules/UniqueOperationNames.php index 761ce2cba..bc9c19910 100644 --- a/src/Validator/Rules/UniqueOperationNames.php +++ b/src/Validator/Rules/UniqueOperationNames.php @@ -9,6 +9,7 @@ use GraphQL\Language\AST\NodeKind; use GraphQL\Language\AST\OperationDefinitionNode; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Validator\ValidationContext; use function sprintf; @@ -22,7 +23,7 @@ public function getVisitor(ValidationContext $context) $this->knownOperationNames = []; return [ - NodeKind::OPERATION_DEFINITION => function (OperationDefinitionNode $node) use ($context) { + NodeKind::OPERATION_DEFINITION => function (OperationDefinitionNode $node) use ($context) : VisitorOperation { $operationName = $node->name; if ($operationName !== null) { @@ -38,7 +39,7 @@ public function getVisitor(ValidationContext $context) return Visitor::skipNode(); }, - NodeKind::FRAGMENT_DEFINITION => static function () { + NodeKind::FRAGMENT_DEFINITION => static function () : VisitorOperation { return Visitor::skipNode(); }, ]; diff --git a/src/Validator/Rules/UniqueVariableNames.php b/src/Validator/Rules/UniqueVariableNames.php index f050a7342..8292e845a 100644 --- a/src/Validator/Rules/UniqueVariableNames.php +++ b/src/Validator/Rules/UniqueVariableNames.php @@ -21,10 +21,10 @@ public function getVisitor(ValidationContext $context) $this->knownVariableNames = []; return [ - NodeKind::OPERATION_DEFINITION => function () { + NodeKind::OPERATION_DEFINITION => function () : void { $this->knownVariableNames = []; }, - NodeKind::VARIABLE_DEFINITION => function (VariableDefinitionNode $node) use ($context) { + NodeKind::VARIABLE_DEFINITION => function (VariableDefinitionNode $node) use ($context) : void { $variableName = $node->variable->name->value; if (empty($this->knownVariableNames[$variableName])) { $this->knownVariableNames[$variableName] = $node->variable->name; diff --git a/src/Validator/Rules/ValuesOfCorrectType.php b/src/Validator/Rules/ValuesOfCorrectType.php index 2e70abff6..53b15423d 100644 --- a/src/Validator/Rules/ValuesOfCorrectType.php +++ b/src/Validator/Rules/ValuesOfCorrectType.php @@ -20,6 +20,7 @@ use GraphQL\Language\AST\VariableNode; use GraphQL\Language\Printer; use GraphQL\Language\Visitor; +use GraphQL\Language\VisitorOperation; use GraphQL\Type\Definition\EnumType; use GraphQL\Type\Definition\EnumValueDefinition; use GraphQL\Type\Definition\InputObjectType; @@ -51,11 +52,11 @@ public function getVisitor(ValidationContext $context) return [ NodeKind::FIELD => [ - 'enter' => static function (FieldNode $node) use (&$fieldName) { + 'enter' => static function (FieldNode $node) use (&$fieldName) : void { $fieldName = $node->name->value; }, ], - NodeKind::NULL => static function (NullValueNode $node) use ($context, &$fieldName) { + NodeKind::NULL => static function (NullValueNode $node) use ($context, &$fieldName) : void { $type = $context->getInputType(); if (! ($type instanceof NonNull)) { return; @@ -68,7 +69,7 @@ public function getVisitor(ValidationContext $context) ) ); }, - NodeKind::LST => function (ListValueNode $node) use ($context, &$fieldName) { + NodeKind::LST => function (ListValueNode $node) use ($context, &$fieldName) : ?VisitorOperation { // Note: TypeInfo will traverse into a list's item type, so look to the // parent input type to check if it is a list. $type = Type::getNullableType($context->getParentInputType()); @@ -77,6 +78,8 @@ public function getVisitor(ValidationContext $context) return Visitor::skipNode(); } + + return null; }, NodeKind::OBJECT => function (ObjectValueNode $node) use ($context, &$fieldName) { // Note: TypeInfo will traverse into a list's item type, so look to the @@ -93,7 +96,7 @@ public function getVisitor(ValidationContext $context) $nodeFields = iterator_to_array($node->fields); $fieldNodeMap = array_combine( array_map( - static function ($field) { + static function ($field) : string { return $field->name->value; }, $nodeFields @@ -114,7 +117,7 @@ static function ($field) { ); } }, - NodeKind::OBJECT_FIELD => static function (ObjectFieldNode $node) use ($context) { + NodeKind::OBJECT_FIELD => static function (ObjectFieldNode $node) use ($context) : void { $parentType = Type::getNamedType($context->getParentInputType()); /** @var ScalarType|EnumType|InputObjectType|ListOfType|NonNull $fieldType */ $fieldType = $context->getInputType(); @@ -137,7 +140,7 @@ static function ($field) { ) ); }, - NodeKind::ENUM => function (EnumValueNode $node) use ($context, &$fieldName) { + NodeKind::ENUM => function (EnumValueNode $node) use ($context, &$fieldName) : void { $type = Type::getNamedType($context->getInputType()); if (! $type instanceof EnumType) { $this->isValidScalar($context, $node, $fieldName); @@ -156,16 +159,16 @@ static function ($field) { ); } }, - NodeKind::INT => function (IntValueNode $node) use ($context, &$fieldName) { + NodeKind::INT => function (IntValueNode $node) use ($context, &$fieldName) : void { $this->isValidScalar($context, $node, $fieldName); }, - NodeKind::FLOAT => function (FloatValueNode $node) use ($context, &$fieldName) { + NodeKind::FLOAT => function (FloatValueNode $node) use ($context, &$fieldName) : void { $this->isValidScalar($context, $node, $fieldName); }, - NodeKind::STRING => function (StringValueNode $node) use ($context, &$fieldName) { + NodeKind::STRING => function (StringValueNode $node) use ($context, &$fieldName) : void { $this->isValidScalar($context, $node, $fieldName); }, - NodeKind::BOOLEAN => function (BooleanValueNode $node) use ($context, &$fieldName) { + NodeKind::BOOLEAN => function (BooleanValueNode $node) use ($context, &$fieldName) : void { $this->isValidScalar($context, $node, $fieldName); }, ]; diff --git a/src/Validator/Rules/VariablesAreInputTypes.php b/src/Validator/Rules/VariablesAreInputTypes.php index 5dc27b433..a1daafff0 100644 --- a/src/Validator/Rules/VariablesAreInputTypes.php +++ b/src/Validator/Rules/VariablesAreInputTypes.php @@ -18,7 +18,7 @@ class VariablesAreInputTypes extends ValidationRule public function getVisitor(ValidationContext $context) { return [ - NodeKind::VARIABLE_DEFINITION => static function (VariableDefinitionNode $node) use ($context) { + NodeKind::VARIABLE_DEFINITION => static function (VariableDefinitionNode $node) use ($context) : void { $type = TypeInfo::typeFromAST($context->getSchema(), $node->type); // If the variable type is not an input type, return an error. diff --git a/src/Validator/Rules/VariablesInAllowedPosition.php b/src/Validator/Rules/VariablesInAllowedPosition.php index a3932fd92..717bd6563 100644 --- a/src/Validator/Rules/VariablesInAllowedPosition.php +++ b/src/Validator/Rules/VariablesInAllowedPosition.php @@ -32,10 +32,10 @@ public function getVisitor(ValidationContext $context) { return [ NodeKind::OPERATION_DEFINITION => [ - 'enter' => function () { + 'enter' => function () : void { $this->varDefMap = []; }, - 'leave' => function (OperationDefinitionNode $operation) use ($context) { + 'leave' => function (OperationDefinitionNode $operation) use ($context) : void { $usages = $context->getRecursiveVariableUsages($operation); foreach ($usages as $usage) { @@ -68,7 +68,7 @@ public function getVisitor(ValidationContext $context) } }, ], - NodeKind::VARIABLE_DEFINITION => function (VariableDefinitionNode $varDefNode) { + NodeKind::VARIABLE_DEFINITION => function (VariableDefinitionNode $varDefNode) : void { $this->varDefMap[$varDefNode->variable->name->value] = $varDefNode; }, ]; diff --git a/src/Validator/ValidationContext.php b/src/Validator/ValidationContext.php index 67f9fbb0c..30ff56cf8 100644 --- a/src/Validator/ValidationContext.php +++ b/src/Validator/ValidationContext.php @@ -105,13 +105,13 @@ private function getVariableUsages(HasSelectionSet $node) Visitor::visitWithTypeInfo( $typeInfo, [ - NodeKind::VARIABLE_DEFINITION => static function () { + NodeKind::VARIABLE_DEFINITION => static function () : bool { return false; }, NodeKind::VARIABLE => static function (VariableNode $variable) use ( &$newUsages, $typeInfo - ) { + ) : void { $newUsages[] = [ 'node' => $variable, 'type' => $typeInfo->getInputType(), diff --git a/tests/Type/QueryPlanTest.php b/tests/Type/QueryPlanTest.php index 0e0e5abfa..20c6f555b 100644 --- a/tests/Type/QueryPlanTest.php +++ b/tests/Type/QueryPlanTest.php @@ -32,7 +32,7 @@ public function testQueryPlan() : void $author = new ObjectType([ 'name' => 'Author', - 'fields' => static function () use ($image, &$article) { + 'fields' => static function () use ($image, &$article) : array { return [ 'id' => ['type' => Type::string()], 'name' => ['type' => Type::string()], @@ -302,7 +302,7 @@ public function testQueryPlanOnInterface() : void { $petType = new InterfaceType([ 'name' => 'Pet', - 'fields' => static function () { + 'fields' => static function () : array { return [ 'name' => ['type' => Type::string()], ]; @@ -312,10 +312,10 @@ public function testQueryPlanOnInterface() : void $dogType = new ObjectType([ 'name' => 'Dog', 'interfaces' => [$petType], - 'isTypeOf' => static function ($obj) { + 'isTypeOf' => static function ($obj) : bool { return $obj instanceof Dog; }, - 'fields' => static function () { + 'fields' => static function () : array { return [ 'name' => ['type' => Type::string()], 'woofs' => ['type' => Type::boolean()], @@ -372,7 +372,7 @@ public function testQueryPlanOnInterface() : void ) use ( &$hasCalled, &$queryPlan -) { + ) : array { $hasCalled = true; $queryPlan = $info->lookAhead(); diff --git a/tests/Type/ResolveInfoTest.php b/tests/Type/ResolveInfoTest.php index d05a44c35..000711f53 100644 --- a/tests/Type/ResolveInfoTest.php +++ b/tests/Type/ResolveInfoTest.php @@ -28,7 +28,7 @@ public function testFieldSelection() : void $author = new ObjectType([ 'name' => 'Author', - 'fields' => static function () use ($image, &$article) { + 'fields' => static function () use ($image, &$article) : array { return [ 'id' => ['type' => Type::string()], 'name' => ['type' => Type::string()], @@ -224,7 +224,7 @@ public function testMergedFragmentsFieldSelection() : void $author = new ObjectType([ 'name' => 'Author', - 'fields' => static function () use ($image, &$article) { + 'fields' => static function () use ($image, &$article) : array { return [ 'id' => ['type' => Type::string()], 'name' => ['type' => Type::string()], diff --git a/tests/Type/SchemaTest.php b/tests/Type/SchemaTest.php index 37075ec94..9b401a49f 100644 --- a/tests/Type/SchemaTest.php +++ b/tests/Type/SchemaTest.php @@ -46,7 +46,7 @@ public function setUp() : void 'fields' => [ 'fieldName' => [ 'type' => Type::string(), - 'resolve' => static function () { + 'resolve' => static function () : string { return ''; }, ], @@ -90,7 +90,7 @@ public function setUp() : void 'fields' => [ 'getObject' => [ 'type' => $this->interfaceType, - 'resolve' => static function () { + 'resolve' => static function () : array { return []; }, ], diff --git a/tests/Type/StandardTypesTest.php b/tests/Type/StandardTypesTest.php index 00e182079..1f1989142 100644 --- a/tests/Type/StandardTypesTest.php +++ b/tests/Type/StandardTypesTest.php @@ -121,11 +121,11 @@ private function createCustomScalarType($name) { return new CustomScalarType([ 'name' => $name, - 'serialize' => static function () { + 'serialize' => static function () : void { }, - 'parseValue' => static function () { + 'parseValue' => static function () : void { }, - 'parseLiteral' => static function () { + 'parseLiteral' => static function () : void { }, ]); } diff --git a/tests/Type/TypeLoaderTest.php b/tests/Type/TypeLoaderTest.php index ab87c70aa..ddf8a2137 100644 --- a/tests/Type/TypeLoaderTest.php +++ b/tests/Type/TypeLoaderTest.php @@ -54,20 +54,20 @@ public function setUp() : void $this->node = new InterfaceType([ 'name' => 'Node', - 'fields' => function () { + 'fields' => function () : array { $this->calls[] = 'Node.fields'; return [ 'id' => Type::string(), ]; }, - 'resolveType' => static function () { + 'resolveType' => static function () : void { }, ]); $this->content = new InterfaceType([ 'name' => 'Content', - 'fields' => function () { + 'fields' => function () : array { $this->calls[] = 'Content.fields'; return [ @@ -75,7 +75,7 @@ public function setUp() : void 'body' => Type::string(), ]; }, - 'resolveType' => static function () { + 'resolveType' => static function () : void { }, ]); @@ -85,7 +85,7 @@ public function setUp() : void $this->node, $this->content, ], - 'fields' => function () { + 'fields' => function () : array { $this->calls[] = 'BlogStory.fields'; return [ @@ -98,7 +98,7 @@ public function setUp() : void $this->query = new ObjectType([ 'name' => 'Query', - 'fields' => function () { + 'fields' => function () : array { $this->calls[] = 'Query.fields'; return [ @@ -110,7 +110,7 @@ public function setUp() : void $this->mutation = new ObjectType([ 'name' => 'Mutation', - 'fields' => function () { + 'fields' => function () : array { $this->calls[] = 'Mutation.fields'; return [ @@ -158,7 +158,7 @@ public function testSchemaAcceptsTypeLoader() : void 'name' => 'Query', 'fields' => ['a' => Type::string()], ]), - 'typeLoader' => static function () { + 'typeLoader' => static function () : void { }, ]); } @@ -259,7 +259,7 @@ public function testFailsOnNonExistentType() : void { $schema = new Schema([ 'query' => $this->query, - 'typeLoader' => static function () { + 'typeLoader' => static function () : void { }, ]); @@ -273,7 +273,7 @@ public function testFailsOnNonType() : void { $schema = new Schema([ 'query' => $this->query, - 'typeLoader' => static function () { + 'typeLoader' => static function () : stdClass { return new stdClass(); }, ]); @@ -288,7 +288,7 @@ public function testFailsOnInvalidLoad() : void { $schema = new Schema([ 'query' => $this->query, - 'typeLoader' => function () { + 'typeLoader' => function () : InterfaceType { return $this->content; }, ]); @@ -303,7 +303,7 @@ public function testPassesThroughAnExceptionInLoader() : void { $schema = new Schema([ 'query' => $this->query, - 'typeLoader' => static function () { + 'typeLoader' => static function () : void { throw new Exception('This is the exception we are looking for'); }, ]); diff --git a/tests/Type/ValidationTest.php b/tests/Type/ValidationTest.php index ca21338c2..f374643e7 100644 --- a/tests/Type/ValidationTest.php +++ b/tests/Type/ValidationTest.php @@ -13,6 +13,8 @@ use GraphQL\Type\Definition\EnumType; use GraphQL\Type\Definition\InputObjectType; use GraphQL\Type\Definition\InterfaceType; +use GraphQL\Type\Definition\ListOfType; +use GraphQL\Type\Definition\NonNull; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\ScalarType; use GraphQL\Type\Definition\Type; @@ -65,27 +67,27 @@ public function setUp() : void $this->SomeScalarType = new CustomScalarType([ 'name' => 'SomeScalar', - 'serialize' => static function () { + 'serialize' => static function () : void { }, - 'parseValue' => static function () { + 'parseValue' => static function () : void { }, - 'parseLiteral' => static function () { + 'parseLiteral' => static function () : void { }, ]); $this->SomeInterfaceType = new InterfaceType([ 'name' => 'SomeInterface', - 'fields' => function () { + 'fields' => function () : array { return ['f' => ['type' => $this->SomeObjectType]]; }, ]); $this->SomeObjectType = new ObjectType([ 'name' => 'SomeObject', - 'fields' => function () { + 'fields' => function () : array { return ['f' => ['type' => $this->SomeObjectType]]; }, - 'interfaces' => function () { + 'interfaces' => function () : array { return [$this->SomeInterfaceType]; }, ]); @@ -144,19 +146,19 @@ private function withModifiers($types) $types, Utils::map( $types, - static function ($type) { + static function ($type) : ListOfType { return Type::listOf($type); } ), Utils::map( $types, - static function ($type) { + static function ($type) : NonNull { return Type::nonNull($type); } ), Utils::map( $types, - static function ($type) { + static function ($type) : NonNull { return Type::nonNull(Type::listOf($type)); } ) @@ -173,19 +175,19 @@ public function testRejectsTypesWithoutNames() : void { $this->assertEachCallableThrows( [ - static function () { + static function () : ObjectType { return new ObjectType([]); }, - static function () { + static function () : EnumType { return new EnumType([]); }, - static function () { + static function () : InputObjectType { return new InputObjectType([]); }, - static function () { + static function () : UnionType { return new UnionType([]); }, - static function () { + static function () : InterfaceType { return new InterfaceType([]); }, ], @@ -335,7 +337,7 @@ public function testRejectsASchemaWithoutAQueryType() : void private function formatLocations(Error $error) { - return Utils::map($error->getLocations(), static function (SourceLocation $loc) { + return Utils::map($error->getLocations(), static function (SourceLocation $loc) : array { return ['line' => $loc->line, 'column' => $loc->column]; }); } @@ -348,7 +350,7 @@ private function formatLocations(Error $error) */ private function formatErrors(array $errors, $withLocation = true) { - return Utils::map($errors, function (Error $error) use ($withLocation) { + return Utils::map($errors, function (Error $error) use ($withLocation) : array { if (! $withLocation) { return [ 'message' => $error->getMessage() ]; } @@ -641,7 +643,7 @@ public function testRejectsAnObjectTypeWithMissingFields() : void $manualSchema2 = $this->schemaWithFieldType( new ObjectType([ 'name' => 'IncompleteObject', - 'fields' => static function () { + 'fields' => static function () : array { return []; }, ]) @@ -2355,7 +2357,7 @@ interface AnotherInterface { public function testRejectsDifferentInstancesOfTheSameType() : void { // Invalid: always creates new instance vs returning one from registry - $typeLoader = static function ($name) { + $typeLoader = static function ($name) : ?ObjectType { switch ($name) { case 'Query': return new ObjectType([ diff --git a/tests/Utils/ExtractTypesTest.php b/tests/Utils/ExtractTypesTest.php index 757c8ce8a..be2de6dfe 100644 --- a/tests/Utils/ExtractTypesTest.php +++ b/tests/Utils/ExtractTypesTest.php @@ -65,7 +65,7 @@ public function setUp() : void $this->content = new InterfaceType([ 'name' => 'Content', - 'fields' => function () { + 'fields' => function () : array { return [ 'title' => Type::string(), 'body' => Type::string(), @@ -82,7 +82,7 @@ public function setUp() : void $this->node, $this->content, ], - 'fields' => function () { + 'fields' => function () : array { return [ $this->node->getField('id'), $this->content->getField('title'), @@ -100,7 +100,7 @@ public function setUp() : void $this->node, $this->content, ], - 'fields' => function () { + 'fields' => function () : array { return [ 'id' => $this->node->getField('id'), 'title' => $this->content->getField('title'), @@ -119,7 +119,7 @@ public function setUp() : void $this->node, $this->content, ], - 'fields' => function () { + 'fields' => function () : array { return [ 'id' => $this->node->getField('id'), 'title' => $this->content->getField('title'), @@ -145,7 +145,7 @@ public function setUp() : void 'interfaces' => [ $this->node, ], - 'fields' => function () { + 'fields' => function () : array { return [ 'id' => $this->node->getField('id'), 'author' => $this->user, @@ -162,7 +162,7 @@ public function setUp() : void 'interfaces' => [ $this->node, ], - 'fields' => function () { + 'fields' => function () : array { return [ 'id' => $this->node->getField('id'), 'name' => Type::string(), @@ -175,7 +175,7 @@ public function setUp() : void 'interfaces' => [ $this->node, ], - 'fields' => function () { + 'fields' => function () : array { return [ 'id' => $this->node->getField('id'), 'name' => Type::string(), diff --git a/tests/Utils/MixedStoreTest.php b/tests/Utils/MixedStoreTest.php index fd04d2e0c..e23460daf 100644 --- a/tests/Utils/MixedStoreTest.php +++ b/tests/Utils/MixedStoreTest.php @@ -38,7 +38,7 @@ public function getPossibleValues() 'a', [], new stdClass(), - static function () { + static function () : void { }, new MixedStore(), ]; @@ -124,7 +124,7 @@ public function testAcceptsObjectKeys() : void $this->assertAcceptsKeyValue(new stdClass(), $value); $this->assertAcceptsKeyValue(new MixedStore(), $value); $this->assertAcceptsKeyValue( - static function () { + static function () : void { }, $value ); diff --git a/tests/Utils/SchemaExtenderTest.php b/tests/Utils/SchemaExtenderTest.php index 61cdb18a0..a7d9729bc 100644 --- a/tests/Utils/SchemaExtenderTest.php +++ b/tests/Utils/SchemaExtenderTest.php @@ -68,7 +68,7 @@ public function setUp() : void $SomeInterfaceType = new InterfaceType([ 'name' => 'SomeInterface', - 'fields' => static function () use (&$SomeInterfaceType) { + 'fields' => static function () use (&$SomeInterfaceType) : array { return [ 'name' => [ 'type' => Type::string()], 'some' => [ 'type' => $SomeInterfaceType], @@ -79,7 +79,7 @@ public function setUp() : void $FooType = new ObjectType([ 'name' => 'Foo', 'interfaces' => [$SomeInterfaceType], - 'fields' => static function () use ($SomeInterfaceType, &$FooType) { + 'fields' => static function () use ($SomeInterfaceType, &$FooType) : array { return [ 'name' => [ 'type' => Type::string() ], 'some' => [ 'type' => $SomeInterfaceType ], @@ -184,7 +184,7 @@ public function setUp() : void $testSchemaAst = Parser::parse(SchemaPrinter::doPrint($this->testSchema)); - $this->testSchemaDefinitions = array_map(static function ($node) { + $this->testSchemaDefinitions = array_map(static function ($node) : string { return Printer::doPrint($node); }, iterator_to_array($testSchemaAst->definitions->getIterator())); @@ -1156,19 +1156,19 @@ public function testMayExtendMutationsAndSubscriptions() $mutationSchema = new Schema([ 'query' => new ObjectType([ 'name' => 'Query', - 'fields' => static function () { + 'fields' => static function () : array { return [ 'queryField' => [ 'type' => Type::string() ] ]; }, ]), 'mutation' => new ObjectType([ 'name' => 'Mutation', - 'fields' => static function () { + 'fields' => static function () : array { return [ 'mutationField' => ['type' => Type::string() ] ]; }, ]), 'subscription' => new ObjectType([ 'name' => 'Subscription', - 'fields' => static function () { + 'fields' => static function () : array { return ['subscriptionField' => ['type' => Type::string()]]; }, ]), @@ -1357,7 +1357,7 @@ public function testDoesNotAllowReplacingACustomDirective() */ public function testDoesNotAllowReplacingAnExistingType() { - $existingTypeError = static function ($type) { + $existingTypeError = static function ($type) : string { return 'Type "' . $type . '" already exists in the schema. It cannot also be defined in this type definition.'; }; @@ -1433,7 +1433,7 @@ enum SomeEnum */ public function testDoesNotAllowReplacingAnExistingField() { - $existingFieldError = static function (string $type, string $field) { + $existingFieldError = static function (string $type, string $field) : string { return 'Field "' . $type . '.' . $field . '" already exists in the schema. It cannot also be defined in this type extension.'; }; @@ -1786,7 +1786,7 @@ public function testSchemaExtensionASTAreAvailableFromSchemaObject() '), implode( "\n", - array_map(static function ($node) { + array_map(static function ($node) : string { return Printer::doPrint($node) . "\n"; }, $nodes) ) @@ -1879,7 +1879,7 @@ public function testOriginalResolversArePreserved() 'fields' => [ 'hello' => [ 'type' => Type::string(), - 'resolve' => static function () { + 'resolve' => static function () : string { return 'Hello World!'; }, ], diff --git a/tests/Validator/OverlappingFieldsCanBeMergedTest.php b/tests/Validator/OverlappingFieldsCanBeMergedTest.php index e66ee71f1..9b3879431 100644 --- a/tests/Validator/OverlappingFieldsCanBeMergedTest.php +++ b/tests/Validator/OverlappingFieldsCanBeMergedTest.php @@ -704,7 +704,7 @@ private function getSchema() $SomeBox = new InterfaceType([ 'name' => 'SomeBox', - 'fields' => static function () use (&$SomeBox) { + 'fields' => static function () use (&$SomeBox) : array { return [ 'deepBox' => ['type' => $SomeBox], 'unrelatedField' => ['type' => Type::string()], @@ -715,7 +715,7 @@ private function getSchema() $StringBox = new ObjectType([ 'name' => 'StringBox', 'interfaces' => [$SomeBox], - 'fields' => static function () use (&$StringBox, &$IntBox) { + 'fields' => static function () use (&$StringBox, &$IntBox) : array { return [ 'scalar' => ['type' => Type::string()], 'deepBox' => ['type' => $StringBox], @@ -730,7 +730,7 @@ private function getSchema() $IntBox = new ObjectType([ 'name' => 'IntBox', 'interfaces' => [$SomeBox], - 'fields' => static function () use (&$StringBox, &$IntBox) { + 'fields' => static function () use (&$StringBox, &$IntBox) : array { return [ 'scalar' => ['type' => Type::int()], 'deepBox' => ['type' => $IntBox], diff --git a/tests/Validator/QueryComplexityTest.php b/tests/Validator/QueryComplexityTest.php index d47c9c5b1..0a14fb966 100644 --- a/tests/Validator/QueryComplexityTest.php +++ b/tests/Validator/QueryComplexityTest.php @@ -199,10 +199,10 @@ public function testSkippedWhenThereAreOtherValidationErrors() : void $reportedError = new Error('OtherValidatorError'); $otherRule = new CustomValidationRule( 'otherRule', - static function (ValidationContext $context) use ($reportedError) { + static function (ValidationContext $context) use ($reportedError) : array { return [ NodeKind::OPERATION_DEFINITION => [ - 'leave' => static function () use ($context, $reportedError) { + 'leave' => static function () use ($context, $reportedError) : void { $context->reportError($reportedError); }, ], diff --git a/tests/Validator/ValidatorTestCase.php b/tests/Validator/ValidatorTestCase.php index 641039835..0944f0e5c 100644 --- a/tests/Validator/ValidatorTestCase.php +++ b/tests/Validator/ValidatorTestCase.php @@ -64,7 +64,7 @@ public static function getTestSchema() $Canine = new InterfaceType([ 'name' => 'Canine', - 'fields' => static function () { + 'fields' => static function () : array { return [ 'name' => [ 'type' => Type::string(), @@ -111,7 +111,7 @@ public static function getTestSchema() $Cat = new ObjectType([ 'name' => 'Cat', - 'fields' => static function () use (&$FurColor) { + 'fields' => static function () use (&$FurColor) : array { return [ 'name' => [ 'type' => Type::string(), @@ -142,7 +142,7 @@ public static function getTestSchema() $Human = new ObjectType([ 'name' => 'Human', 'interfaces' => [$Being, $Intelligent], - 'fields' => static function () use (&$Human, $Pet) { + 'fields' => static function () use (&$Human, $Pet) : array { return [ 'name' => [ 'type' => Type::string(), @@ -300,10 +300,10 @@ public static function getTestSchema() 'serialize' => static function ($value) { return $value; }, - 'parseLiteral' => static function ($node) { + 'parseLiteral' => static function ($node) : void { throw new Exception('Invalid scalar is always invalid: ' . $node->value); }, - 'parseValue' => static function ($node) { + 'parseValue' => static function ($node) : void { throw new Exception('Invalid scalar is always invalid: ' . $node); }, ]);