diff --git a/composer.json b/composer.json index 7ace361..113e79d 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "ext-mbstring": "*" }, "require-dev": { - "doctrine/coding-standard": "^5.0", + "doctrine/coding-standard": "^6.0", "phpbench/phpbench": "^0.14.0", "phpstan/phpstan": "^0.11.4", "phpstan/phpstan-phpunit": "^0.11.0", diff --git a/src/Error/Error.php b/src/Error/Error.php index e0c36e3..2e78221 100644 --- a/src/Error/Error.php +++ b/src/Error/Error.php @@ -122,13 +122,13 @@ class Error extends Exception implements JsonSerializable, ClientAware if ($previous instanceof ClientAware) { $this->isClientSafe = $previous->isClientSafe(); - $this->category = $previous->getCategory() ?: static::CATEGORY_INTERNAL; + $this->category = $previous->getCategory() ?: self::CATEGORY_INTERNAL; } elseif ($previous) { $this->isClientSafe = false; - $this->category = static::CATEGORY_INTERNAL; + $this->category = self::CATEGORY_INTERNAL; } else { $this->isClientSafe = true; - $this->category = static::CATEGORY_GRAPHQL; + $this->category = self::CATEGORY_GRAPHQL; } } @@ -148,10 +148,10 @@ class Error extends Exception implements JsonSerializable, ClientAware if ($error instanceof self) { if ($error->path && $error->nodes) { return $error; - } else { - $nodes = $nodes ?: $error->nodes; - $path = $path ?: $error->path; } + + $nodes = $nodes ?: $error->nodes; + $path = $path ?: $error->path; } $source = $positions = $originalError = null; diff --git a/src/Error/InvariantViolation.php b/src/Error/InvariantViolation.php index 6f9cfad..24d6dbc 100644 --- a/src/Error/InvariantViolation.php +++ b/src/Error/InvariantViolation.php @@ -7,8 +7,6 @@ namespace GraphQL\Error; use LogicException; /** - * Class InvariantVoilation - * * Note: * This exception should not inherit base Error exception as it is raised when there is an error somewhere in * user-land code diff --git a/src/Error/UserError.php b/src/Error/UserError.php index 67bb9bb..2ffe811 100644 --- a/src/Error/UserError.php +++ b/src/Error/UserError.php @@ -7,8 +7,6 @@ namespace GraphQL\Error; use RuntimeException; /** - * Class UserError - * * Error caused by actions of GraphQL clients. Can be safely displayed to a client... */ class UserError extends RuntimeException implements ClientAware diff --git a/src/Executor/Promise/Adapter/SyncPromise.php b/src/Executor/Promise/Adapter/SyncPromise.php index 91e139c..26aecd6 100644 --- a/src/Executor/Promise/Adapter/SyncPromise.php +++ b/src/Executor/Promise/Adapter/SyncPromise.php @@ -13,8 +13,6 @@ use function is_object; use function method_exists; /** - * Class SyncPromise - * * Simplistic (yet full-featured) implementation of Promises A+ spec for regular PHP `sync` mode * (using queue to defer promises execution) */ diff --git a/src/Executor/Promise/Adapter/SyncPromiseAdapter.php b/src/Executor/Promise/Adapter/SyncPromiseAdapter.php index 2df02af..e5900a9 100644 --- a/src/Executor/Promise/Adapter/SyncPromiseAdapter.php +++ b/src/Executor/Promise/Adapter/SyncPromiseAdapter.php @@ -160,7 +160,9 @@ class SyncPromiseAdapter implements PromiseAdapter if ($syncPromise->state === SyncPromise::FULFILLED) { return $syncPromise->result; - } elseif ($syncPromise->state === SyncPromise::REJECTED) { + } + + if ($syncPromise->state === SyncPromise::REJECTED) { throw $syncPromise->result; } diff --git a/src/Executor/ReferenceExecutor.php b/src/Executor/ReferenceExecutor.php index 90030de..7b54afc 100644 --- a/src/Executor/ReferenceExecutor.php +++ b/src/Executor/ReferenceExecutor.php @@ -182,6 +182,7 @@ class ReferenceExecutor implements ExecutorImplementation } Utils::invariant($operation, 'Has operation if no errors.'); Utils::invariant($variableValues !== null, 'Has variables if no errors.'); + return new ExecutionContext( $schema, $fragments, @@ -206,6 +207,7 @@ class ReferenceExecutor implements ExecutorImplementation // resolved Promise. $data = $this->executeOperation($this->exeContext->operation, $this->exeContext->rootValue); $result = $this->buildResponse($data); + // Note: we deviate here from the reference implementation a bit by always returning promise // But for the "sync" case it is always fulfilled return $this->isPromise($result) @@ -228,6 +230,7 @@ class ReferenceExecutor implements ExecutorImplementation if ($data !== null) { $data = (array) $data; } + return new ExecutionResult($data, $this->exeContext->errors); } @@ -257,13 +260,16 @@ class ReferenceExecutor implements ExecutorImplementation null, function ($error) { $this->exeContext->addError($error); + return $this->exeContext->promises->createFulfilled(null); } ); } + return $result; } catch (Error $error) { $this->exeContext->addError($error); + return null; } } @@ -286,6 +292,7 @@ class ReferenceExecutor implements ExecutorImplementation [$operation] ); } + return $queryType; case 'mutation': $mutationType = $schema->getMutationType(); @@ -295,6 +302,7 @@ class ReferenceExecutor implements ExecutorImplementation [$operation] ); } + return $mutationType; case 'subscription': $subscriptionType = $schema->getSubscriptionType(); @@ -304,6 +312,7 @@ class ReferenceExecutor implements ExecutorImplementation [$operation] ); } + return $subscriptionType; default: throw new Error( @@ -378,6 +387,7 @@ class ReferenceExecutor implements ExecutorImplementation break; } } + return $fields; } @@ -407,10 +417,8 @@ class ReferenceExecutor implements ExecutorImplementation $node, $variableValues ); - if (isset($include['if']) && $include['if'] === false) { - return false; - } - return true; + + return ! isset($include['if']) || $include['if'] !== false; } /** @@ -445,6 +453,7 @@ class ReferenceExecutor implements ExecutorImplementation if ($conditionalType instanceof AbstractType) { return $this->exeContext->schema->isPossibleType($conditionalType, $type); } + return false; } @@ -474,10 +483,12 @@ class ReferenceExecutor implements ExecutorImplementation if ($promise) { return $promise->then(static function ($resolvedResult) use ($responseName, $results) { $results[$responseName] = $resolvedResult; + return $results; }); } $results[$responseName] = $result; + return $results; }, [] @@ -487,6 +498,7 @@ class ReferenceExecutor implements ExecutorImplementation return self::fixResultsIfEmptyArray($resolvedResults); }); } + return self::fixResultsIfEmptyArray($result); } @@ -554,6 +566,7 @@ class ReferenceExecutor implements ExecutorImplementation $path, $result ); + return $result; } @@ -578,12 +591,17 @@ class ReferenceExecutor implements ExecutorImplementation $typeNameMetaFieldDef = $typeNameMetaFieldDef ?: Introspection::typeNameMetaFieldDef(); if ($fieldName === $schemaMetaFieldDef->name && $schema->getQueryType() === $parentType) { return $schemaMetaFieldDef; - } elseif ($fieldName === $typeMetaFieldDef->name && $schema->getQueryType() === $parentType) { + } + + if ($fieldName === $typeMetaFieldDef->name && $schema->getQueryType() === $parentType) { return $typeMetaFieldDef; - } elseif ($fieldName === $typeNameMetaFieldDef->name) { + } + + if ($fieldName === $typeNameMetaFieldDef->name) { return $typeNameMetaFieldDef; } $tmp = $parentType->getFields(); + return $tmp[$fieldName] ?? null; } @@ -610,6 +628,7 @@ class ReferenceExecutor implements ExecutorImplementation $fieldNode, $this->exeContext->variableValues ); + return $resolveFn($source, $args, $context, $info); } catch (Exception $error) { return $error; @@ -663,15 +682,18 @@ class ReferenceExecutor implements ExecutorImplementation null, function ($error) use ($exeContext) { $exeContext->addError($error); + return $this->exeContext->promises->createFulfilled(null); } ); } + return $completed; } catch (Error $err) { // If `completeValueWithLocatedError` returned abruptly (threw an error), log the error // and return null. $exeContext->addError($err); + return null; } } @@ -716,6 +738,7 @@ class ReferenceExecutor implements ExecutorImplementation } ); } + return $completed; } catch (Exception $error) { throw Error::createLocatedError($error, $fieldNodes, $path); @@ -786,6 +809,7 @@ class ReferenceExecutor implements ExecutorImplementation 'Cannot return null for non-nullable field ' . $info->parentType . '.' . $info->fieldName . '.' ); } + return $completed; } // If result is null-like, return null. @@ -863,8 +887,10 @@ class ReferenceExecutor implements ExecutorImplementation Utils::printSafe($promise) )); } + return $promise; } + return null; } @@ -891,6 +917,7 @@ class ReferenceExecutor implements ExecutorImplementation return $callback($resolved, $value); }); } + return $callback($previous, $value); }, $initialValue @@ -928,6 +955,7 @@ class ReferenceExecutor implements ExecutorImplementation } $completedItems[] = $completedItem; } + return $containsPromise ? $this->exeContext->promises->all($completedItems) : $completedItems; } @@ -1001,6 +1029,7 @@ class ReferenceExecutor implements ExecutorImplementation ); }); } + return $this->completeObjectValue( $this->ensureValidRuntimeType( $runtimeType, @@ -1076,9 +1105,11 @@ class ReferenceExecutor implements ExecutorImplementation return $possibleTypes[$index]; } } + return null; }); } + return null; } @@ -1111,6 +1142,7 @@ class ReferenceExecutor implements ExecutorImplementation if (! $isTypeOfResult) { throw $this->invalidReturnTypeError($returnType, $result, $fieldNodes); } + return $this->collectAndExecuteSubfields( $returnType, $fieldNodes, @@ -1123,6 +1155,7 @@ class ReferenceExecutor implements ExecutorImplementation throw $this->invalidReturnTypeError($returnType, $result, $fieldNodes); } } + return $this->collectAndExecuteSubfields( $returnType, $fieldNodes, @@ -1164,6 +1197,7 @@ class ReferenceExecutor implements ExecutorImplementation &$result ) { $subFieldNodes = $this->collectSubFields($returnType, $fieldNodes); + return $this->executeFields($returnType, $result, $path, $subFieldNodes); } @@ -1189,6 +1223,7 @@ class ReferenceExecutor implements ExecutorImplementation } $this->subFieldCache[$returnType][$fieldNodes] = $subFieldNodes; } + return $this->subFieldCache[$returnType][$fieldNodes]; } @@ -1222,6 +1257,7 @@ class ReferenceExecutor implements ExecutorImplementation if (! $containsPromise) { return self::fixResultsIfEmptyArray($finalResults); } + // Otherwise, results is a map from field name to the result // of resolving that field, which is possibly a promise. Return // a promise that will return this same map, but with any @@ -1241,6 +1277,7 @@ class ReferenceExecutor implements ExecutorImplementation if ($results === []) { return new stdClass(); } + return $results; } @@ -1260,11 +1297,13 @@ class ReferenceExecutor implements ExecutorImplementation $keys = array_keys($assoc); $valuesAndPromises = array_values($assoc); $promise = $this->exeContext->promises->all($valuesAndPromises); + return $promise->then(static function ($values) use ($keys) { $resolvedResults = []; foreach ($values as $i => $value) { $resolvedResults[$keys[$i]] = $value; } + return self::fixResultsIfEmptyArray($resolvedResults); }); } @@ -1318,6 +1357,7 @@ class ReferenceExecutor implements ExecutorImplementation ) ); } + return $runtimeType; } } diff --git a/src/Experimental/Executor/Collector.php b/src/Experimental/Executor/Collector.php index 34f1e0e..99131ba 100644 --- a/src/Experimental/Executor/Collector.php +++ b/src/Experimental/Executor/Collector.php @@ -86,11 +86,13 @@ class Collector } else { $this->runtime->addError(new Error('Must provide an operation.')); } + return; } if ($hasMultipleAssumedOperations) { $this->runtime->addError(new Error('Must provide operation name if query contains multiple operations.')); + return; } @@ -211,7 +213,9 @@ class Collector if (isset($this->visitedFragments[$fragmentName])) { continue; - } elseif (! isset($this->fragments[$fragmentName])) { + } + + if (! isset($this->fragments[$fragmentName])) { $this->runtime->addError(new Error( sprintf('Fragment "%s" does not exist.', $fragmentName), $selection diff --git a/src/Experimental/Executor/CoroutineExecutor.php b/src/Experimental/Executor/CoroutineExecutor.php index b089fad..d985633 100644 --- a/src/Experimental/Executor/CoroutineExecutor.php +++ b/src/Experimental/Executor/CoroutineExecutor.php @@ -147,6 +147,7 @@ class CoroutineExecutor implements Runtime, ExecutorImplementation if ($emptyObjectAsStdClass && empty($array)) { return new stdClass(); } + return $array; } @@ -155,6 +156,7 @@ class CoroutineExecutor implements Runtime, ExecutorImplementation foreach ($value as $key => $item) { $array[$key] = self::resultToArray($item); } + return $array; } @@ -365,6 +367,7 @@ class CoroutineExecutor implements Runtime, ExecutorImplementation // short-circuit evaluation for __typename if ($ctx->shared->fieldName === Introspection::TYPE_NAME_FIELD_NAME) { $ctx->result->{$ctx->shared->resultName} = $ctx->type->name; + return; } diff --git a/src/Language/AST/Location.php b/src/Language/AST/Location.php index 7ea05ad..72135fc 100644 --- a/src/Language/AST/Location.php +++ b/src/Language/AST/Location.php @@ -59,6 +59,7 @@ class Location $tmp = new static(); $tmp->start = $start; $tmp->end = $end; + return $tmp; } diff --git a/src/Language/AST/NodeList.php b/src/Language/AST/NodeList.php index 2e7de79..cede5a4 100644 --- a/src/Language/AST/NodeList.php +++ b/src/Language/AST/NodeList.php @@ -105,6 +105,7 @@ class NodeList implements ArrayAccess, IteratorAggregate, Countable if ($list instanceof self) { $list = $list->nodes; } + return new NodeList(array_merge($this->nodes, $list)); } diff --git a/src/Language/Lexer.php b/src/Language/Lexer.php index fb4157c..3aad4dd 100644 --- a/src/Language/Lexer.php +++ b/src/Language/Lexer.php @@ -23,6 +23,22 @@ use function preg_match; */ class Lexer { + private const TOKEN_BANG = 33; + private const TOKEN_HASH = 35; + private const TOKEN_DOLLAR = 36; + private const TOKEN_AMP = 38; + private const TOKEN_PAREN_L = 40; + private const TOKEN_PAREN_R = 41; + private const TOKEN_DOT = 46; + private const TOKEN_COLON = 58; + private const TOKEN_EQUALS = 61; + private const TOKEN_AT = 64; + private const TOKEN_BRACKET_L = 91; + private const TOKEN_BRACKET_R = 93; + private const TOKEN_BRACE_L = 123; + private const TOKEN_PIPE = 124; + private const TOKEN_BRACE_R = 125; + /** @var Source */ public $source; @@ -92,7 +108,8 @@ class Lexer */ public function advance() { - $this->lastToken = $this->token; + $this->lastToken = $this->token; + return $this->token = $this->lookahead(); } @@ -131,44 +148,45 @@ class Lexer [, $code, $bytes] = $this->readChar(true); switch ($code) { - case 33: // ! + case self::TOKEN_BANG: return new Token(Token::BANG, $position, $position + 1, $line, $col, $prev); - case 35: // # + case self::TOKEN_HASH: // # $this->moveStringCursor(-1, -1 * $bytes); return $this->readComment($line, $col, $prev); - case 36: // $ + case self::TOKEN_DOLLAR: return new Token(Token::DOLLAR, $position, $position + 1, $line, $col, $prev); - case 38: // & + case self::TOKEN_AMP: return new Token(Token::AMP, $position, $position + 1, $line, $col, $prev); - case 40: // ( + case self::TOKEN_PAREN_L: return new Token(Token::PAREN_L, $position, $position + 1, $line, $col, $prev); - case 41: // ) + case self::TOKEN_PAREN_R: return new Token(Token::PAREN_R, $position, $position + 1, $line, $col, $prev); - case 46: // . + case self::TOKEN_DOT: // . [, $charCode1] = $this->readChar(true); [, $charCode2] = $this->readChar(true); - if ($charCode1 === 46 && $charCode2 === 46) { + if ($charCode1 === self::TOKEN_DOT && $charCode2 === self::TOKEN_DOT) { return new Token(Token::SPREAD, $position, $position + 3, $line, $col, $prev); } break; - case 58: // : + case self::TOKEN_COLON: return new Token(Token::COLON, $position, $position + 1, $line, $col, $prev); - case 61: // = + case self::TOKEN_EQUALS: return new Token(Token::EQUALS, $position, $position + 1, $line, $col, $prev); - case 64: // @ + case self::TOKEN_AT: return new Token(Token::AT, $position, $position + 1, $line, $col, $prev); - case 91: // [ + case self::TOKEN_BRACKET_L: return new Token(Token::BRACKET_L, $position, $position + 1, $line, $col, $prev); - case 93: // ] + case self::TOKEN_BRACKET_R: return new Token(Token::BRACKET_R, $position, $position + 1, $line, $col, $prev); - case 123: // { + case self::TOKEN_BRACE_L: return new Token(Token::BRACE_L, $position, $position + 1, $line, $col, $prev); - case 124: // | + case self::TOKEN_PIPE: return new Token(Token::PIPE, $position, $position + 1, $line, $col, $prev); - case 125: // } + case self::TOKEN_BRACE_R: return new Token(Token::BRACE_R, $position, $position + 1, $line, $col, $prev); + // A-Z case 65: case 66: @@ -227,6 +245,7 @@ class Lexer case 122: return $this->moveStringCursor(-1, -1 * $bytes) ->readName($line, $col, $prev); + // - case 45: // 0-9 @@ -242,6 +261,7 @@ class Lexer case 57: return $this->moveStringCursor(-1, -1 * $bytes) ->readNumber($line, $col, $prev); + // " case 34: [, $nextCode] = $this->readChar(); @@ -564,10 +584,10 @@ class Lexer $prev, BlockString::value($value) ); - } else { - // move cursor back to before the first quote - $this->moveStringCursor(-2, -2); } + + // move cursor back to before the first quote + $this->moveStringCursor(-2, -2); } $this->assertValidBlockStringCharacterCode($code, $this->position); diff --git a/src/Language/Parser.php b/src/Language/Parser.php index 10f0859..f5c9280 100644 --- a/src/Language/Parser.php +++ b/src/Language/Parser.php @@ -439,7 +439,6 @@ class Parser case 'mutation': case 'subscription': return $this->parseOperationDefinition(); - case 'fragment': return $this->parseFragmentDefinition(); } @@ -827,7 +826,9 @@ class Parser 'value' => $token->value === 'true', 'loc' => $this->loc($token), ]); - } elseif ($token->value === 'null') { + } + + if ($token->value === 'null') { $this->lexer->advance(); return new NullValueNode([ diff --git a/src/Language/Printer.php b/src/Language/Printer.php index ff11d50..ae96222 100644 --- a/src/Language/Printer.php +++ b/src/Language/Printer.php @@ -115,6 +115,7 @@ class Printer $varDefs = $this->wrap('(', $this->join($node->variableDefinitions, ', '), ')'); $directives = $this->join($node->directives, ' '); $selectionSet = $node->selectionSet; + // Anonymous queries with no directives or variable definitions can use // the query short form. return ! $name && ! $directives && ! $varDefs && $op === 'query' diff --git a/src/Server/StandardServer.php b/src/Server/StandardServer.php index 63bd140..7b7e627 100644 --- a/src/Server/StandardServer.php +++ b/src/Server/StandardServer.php @@ -151,6 +151,7 @@ class StandardServer StreamInterface $writableBodyStream ) { $result = $this->executePsrRequest($request); + return $this->helper->toPsrResponse($result, $response, $writableBodyStream); } @@ -165,6 +166,7 @@ class StandardServer public function executePsrRequest(ServerRequestInterface $request) { $parsedBody = $this->helper->parsePsrRequest($request); + return $this->executeRequest($parsedBody); } diff --git a/src/Type/Definition/BooleanType.php b/src/Type/Definition/BooleanType.php index 67b8178..56b5f0f 100644 --- a/src/Type/Definition/BooleanType.php +++ b/src/Type/Definition/BooleanType.php @@ -11,9 +11,6 @@ use GraphQL\Language\AST\Node; use GraphQL\Utils\Utils; use function is_bool; -/** - * Class BooleanType - */ class BooleanType extends ScalarType { /** @var string */ diff --git a/src/Type/Definition/CustomScalarType.php b/src/Type/Definition/CustomScalarType.php index 21766ab..50b28ce 100644 --- a/src/Type/Definition/CustomScalarType.php +++ b/src/Type/Definition/CustomScalarType.php @@ -12,9 +12,6 @@ use function call_user_func; use function is_callable; use function sprintf; -/** - * Class CustomScalarType - */ class CustomScalarType extends ScalarType { /** diff --git a/src/Type/Definition/Directive.php b/src/Type/Definition/Directive.php index 9baa7ff..0ffe496 100644 --- a/src/Type/Definition/Directive.php +++ b/src/Type/Definition/Directive.php @@ -12,9 +12,6 @@ use function array_keys; use function in_array; use function is_array; -/** - * Class Directive - */ class Directive { public const DEFAULT_DEPRECATION_REASON = 'No longer supported'; @@ -80,6 +77,7 @@ class Directive public static function includeDirective() { $internal = self::getInternalDirectives(); + return $internal['include']; } @@ -140,24 +138,30 @@ class Directive ]), ]; } + return self::$internalDirectives; } + /** * @return Directive */ public static function skipDirective() { $internal = self::getInternalDirectives(); + return $internal['skip']; } + /** * @return Directive */ public static function deprecatedDirective() { $internal = self::getInternalDirectives(); + return $internal['deprecated']; } + /** * @return bool */ diff --git a/src/Type/Definition/EnumType.php b/src/Type/Definition/EnumType.php index b565a25..dc83d69 100644 --- a/src/Type/Definition/EnumType.php +++ b/src/Type/Definition/EnumType.php @@ -19,9 +19,6 @@ use function is_int; use function is_string; use function sprintf; -/** - * Class EnumType - */ class EnumType extends Type implements InputType, OutputType, LeafType, NullableType, NamedType { /** @var EnumTypeDefinitionNode|null */ @@ -33,7 +30,7 @@ class EnumType extends Type implements InputType, OutputType, LeafType, Nullable /** @var MixedStore */ private $valueLookup; - /** @var \ArrayObject */ + /** @var ArrayObject */ private $nameLookup; /** @var EnumTypeExtensionNode[] */ @@ -71,7 +68,7 @@ class EnumType extends Type implements InputType, OutputType, LeafType, Nullable } /** - * @return \ArrayObject + * @return ArrayObject */ private function getNameLookup() { diff --git a/src/Type/Definition/EnumValueDefinition.php b/src/Type/Definition/EnumValueDefinition.php index 33494be..9454f35 100644 --- a/src/Type/Definition/EnumValueDefinition.php +++ b/src/Type/Definition/EnumValueDefinition.php @@ -6,9 +6,6 @@ namespace GraphQL\Type\Definition; use GraphQL\Language\AST\EnumValueDefinitionNode; -/** - * Class EnumValueDefinition - */ class EnumValueDefinition { /** @var string */ diff --git a/src/Type/Definition/FieldArgument.php b/src/Type/Definition/FieldArgument.php index 33cad0d..3bffe57 100644 --- a/src/Type/Definition/FieldArgument.php +++ b/src/Type/Definition/FieldArgument.php @@ -11,9 +11,6 @@ use function is_array; use function is_string; use function sprintf; -/** - * Class FieldArgument - */ class FieldArgument { /** @var string */ diff --git a/src/Type/Definition/FieldDefinition.php b/src/Type/Definition/FieldDefinition.php index 34ad66f..8f409bf 100644 --- a/src/Type/Definition/FieldDefinition.php +++ b/src/Type/Definition/FieldDefinition.php @@ -81,7 +81,7 @@ class FieldDefinition $this->config = $config; - $this->complexityFn = $config['complexity'] ?? static::DEFAULT_COMPLEXITY_FN; + $this->complexityFn = $config['complexity'] ?? self::DEFAULT_COMPLEXITY_FN; } public static function defineFieldMap(Type $type, $fields) diff --git a/src/Type/Definition/FloatType.php b/src/Type/Definition/FloatType.php index 0e6eba0..e8923ca 100644 --- a/src/Type/Definition/FloatType.php +++ b/src/Type/Definition/FloatType.php @@ -12,9 +12,6 @@ use GraphQL\Language\AST\Node; use GraphQL\Utils\Utils; use function is_numeric; -/** - * Class FloatType - */ class FloatType extends ScalarType { /** @var string */ diff --git a/src/Type/Definition/InputObjectType.php b/src/Type/Definition/InputObjectType.php index 756e142..c921dda 100644 --- a/src/Type/Definition/InputObjectType.php +++ b/src/Type/Definition/InputObjectType.php @@ -15,9 +15,6 @@ use function is_callable; use function is_string; use function sprintf; -/** - * Class InputObjectType - */ class InputObjectType extends Type implements InputType, NullableType, NamedType { /** @var InputObjectTypeDefinitionNode|null */ diff --git a/src/Type/Definition/IntType.php b/src/Type/Definition/IntType.php index 1f59a92..e6176c3 100644 --- a/src/Type/Definition/IntType.php +++ b/src/Type/Definition/IntType.php @@ -14,9 +14,6 @@ use function intval; use function is_bool; use function is_numeric; -/** - * Class IntType - */ class IntType extends ScalarType { // As per the GraphQL Spec, Integers are only treated as valid when a valid diff --git a/src/Type/Definition/InterfaceType.php b/src/Type/Definition/InterfaceType.php index 1c7c389..c13d7fb 100644 --- a/src/Type/Definition/InterfaceType.php +++ b/src/Type/Definition/InterfaceType.php @@ -12,9 +12,6 @@ use function is_callable; use function is_string; use function sprintf; -/** - * Class InterfaceType - */ class InterfaceType extends Type implements AbstractType, OutputType, CompositeType, NullableType, NamedType { /** @var InterfaceTypeDefinitionNode|null */ diff --git a/src/Type/Definition/ListOfType.php b/src/Type/Definition/ListOfType.php index e45bc14..eb8200d 100644 --- a/src/Type/Definition/ListOfType.php +++ b/src/Type/Definition/ListOfType.php @@ -4,9 +4,6 @@ declare(strict_types=1); namespace GraphQL\Type\Definition; -/** - * Class ListOfType - */ class ListOfType extends Type implements WrappingType, OutputType, NullableType, InputType { /** @var ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType */ diff --git a/src/Type/Definition/NonNull.php b/src/Type/Definition/NonNull.php index cc80be0..6799523 100644 --- a/src/Type/Definition/NonNull.php +++ b/src/Type/Definition/NonNull.php @@ -6,9 +6,6 @@ namespace GraphQL\Type\Definition; use GraphQL\Utils\Utils; -/** - * Class NonNull - */ class NonNull extends Type implements WrappingType, OutputType, InputType { /** @var NullableType */ diff --git a/src/Type/Definition/QueryPlan.php b/src/Type/Definition/QueryPlan.php index 7564f96..235066d 100644 --- a/src/Type/Definition/QueryPlan.php +++ b/src/Type/Definition/QueryPlan.php @@ -183,6 +183,7 @@ class QueryPlan ); } } + return $fields; } diff --git a/src/Type/Definition/ResolveInfo.php b/src/Type/Definition/ResolveInfo.php index 83354c0..f2525de 100644 --- a/src/Type/Definition/ResolveInfo.php +++ b/src/Type/Definition/ResolveInfo.php @@ -226,6 +226,7 @@ class ResolveInfo ); } } + return $fields; } } diff --git a/src/Type/Definition/StringType.php b/src/Type/Definition/StringType.php index ebfcf4a..533298f 100644 --- a/src/Type/Definition/StringType.php +++ b/src/Type/Definition/StringType.php @@ -14,9 +14,6 @@ use function is_object; use function is_scalar; use function method_exists; -/** - * Class StringType - */ class StringType extends ScalarType { /** @var string */ diff --git a/src/Type/Definition/Type.php b/src/Type/Definition/Type.php index 5b8e414..69faa1c 100644 --- a/src/Type/Definition/Type.php +++ b/src/Type/Definition/Type.php @@ -194,6 +194,7 @@ abstract class Type implements JsonSerializable public static function getInternalTypes() { trigger_error(__METHOD__ . ' is deprecated. Use Type::getStandardTypes() instead', E_USER_DEPRECATED); + return self::getStandardTypes(); } diff --git a/src/Type/Definition/UnionType.php b/src/Type/Definition/UnionType.php index 8a735e3..3229df4 100644 --- a/src/Type/Definition/UnionType.php +++ b/src/Type/Definition/UnionType.php @@ -14,9 +14,6 @@ use function is_callable; use function is_string; use function sprintf; -/** - * Class UnionType - */ class UnionType extends Type implements AbstractType, OutputType, CompositeType, NullableType, NamedType { /** @var UnionTypeDefinitionNode */ diff --git a/src/Utils/AST.php b/src/Utils/AST.php index 5ef4233..ae01ac5 100644 --- a/src/Utils/AST.php +++ b/src/Utils/AST.php @@ -353,6 +353,7 @@ class AST // No valid return value. return $undefined; } + // Note: we're not doing any checking that this variable is correct. We're // assuming that this query has been validated and the variable usage here // is of the correct type. diff --git a/src/Utils/ASTDefinitionBuilder.php b/src/Utils/ASTDefinitionBuilder.php index 8e452e2..95f8d5a 100644 --- a/src/Utils/ASTDefinitionBuilder.php +++ b/src/Utils/ASTDefinitionBuilder.php @@ -144,7 +144,8 @@ class ASTDefinitionBuilder // Note: While this could make assertions to get the correctly typed // value, that would throw immediately while type system validation // with validateSchema() will produce more actionable results. - $type = $this->internalBuildWrappedType($value->type); + $type = $this->internalBuildWrappedType($value->type); + $config = [ 'name' => $value->name->value, 'type' => $type, diff --git a/src/Utils/MixedStore.php b/src/Utils/MixedStore.php index 2ee1918..469abaa 100644 --- a/src/Utils/MixedStore.php +++ b/src/Utils/MixedStore.php @@ -22,8 +22,6 @@ use function is_string; * * Note: unfortunately when storing array as key - access and modification is O(N) * (yet this should be really rare case and should be avoided when possible) - * - * Class MixedStore */ class MixedStore implements ArrayAccess { diff --git a/src/Utils/SchemaExtender.php b/src/Utils/SchemaExtender.php index 110e750..07a1447 100644 --- a/src/Utils/SchemaExtender.php +++ b/src/Utils/SchemaExtender.php @@ -66,6 +66,7 @@ class SchemaExtender return $type->extensionASTNodes; } + return static::$typeExtensionsMap[$name] ?? null; } @@ -284,6 +285,7 @@ class SchemaExtender } } } + return $interfaces; } diff --git a/src/Utils/SchemaPrinter.php b/src/Utils/SchemaPrinter.php index 023ecb9..9e9e1ca 100644 --- a/src/Utils/SchemaPrinter.php +++ b/src/Utils/SchemaPrinter.php @@ -153,11 +153,8 @@ class SchemaPrinter } $subscriptionType = $schema->getSubscriptionType(); - if ($subscriptionType && $subscriptionType->name !== 'Subscription') { - return false; - } - return true; + return ! $subscriptionType || $subscriptionType->name === 'Subscription'; } private static function printDirective($directive, $options) : string diff --git a/src/Utils/TypeComparators.php b/src/Utils/TypeComparators.php index 24e4b00..2beb942 100644 --- a/src/Utils/TypeComparators.php +++ b/src/Utils/TypeComparators.php @@ -86,18 +86,12 @@ class TypeComparators // If superType type is an abstract type, maybeSubType type may be a currently // possible object type. - if (Type::isAbstractType($superType) && + return Type::isAbstractType($superType) && $maybeSubType instanceof ObjectType && $schema->isPossibleType( $superType, $maybeSubType - ) - ) { - return true; - } - - // Otherwise, the child type is not a valid subtype of the parent type. - return false; + ); } /** @@ -131,13 +125,11 @@ class TypeComparators return false; } - /** @var $typeB ObjectType */ // Determine if the latter type is a possible concrete type of the former. return $schema->isPossibleType($typeA, $typeB); } if ($typeB instanceof AbstractType) { - /** @var $typeA ObjectType */ // Determine if the former type is a possible concrete type of the latter. return $schema->isPossibleType($typeB, $typeA); } diff --git a/src/Utils/TypeInfo.php b/src/Utils/TypeInfo.php index 63c3f4a..89d4ea1 100644 --- a/src/Utils/TypeInfo.php +++ b/src/Utils/TypeInfo.php @@ -28,6 +28,7 @@ use GraphQL\Type\Definition\UnionType; use GraphQL\Type\Definition\WrappingType; use GraphQL\Type\Introspection; use GraphQL\Type\Schema; +use SplStack; use function array_map; use function array_merge; use function array_pop; @@ -35,24 +36,21 @@ use function count; use function is_array; use function sprintf; -/** - * Class TypeInfo - */ class TypeInfo { /** @var Schema */ private $schema; - /** @var \SplStack */ + /** @var SplStack */ private $typeStack; - /** @var \SplStack */ + /** @var SplStack */ private $parentTypeStack; - /** @var \SplStack */ + /** @var SplStack */ private $inputTypeStack; - /** @var \SplStack */ + /** @var SplStack */ private $fieldDefStack; /** @var Directive */ @@ -155,6 +153,7 @@ class TypeInfo if (! $alreadyInMap) { $typeMap[$i] = $type; } + return $typeMap; } diff --git a/src/Validator/Rules/DisableIntrospection.php b/src/Validator/Rules/DisableIntrospection.php index bb2dc3e..6e0efab 100644 --- a/src/Validator/Rules/DisableIntrospection.php +++ b/src/Validator/Rules/DisableIntrospection.php @@ -52,6 +52,6 @@ class DisableIntrospection extends QuerySecurityRule protected function isEnabled() { - return $this->isEnabled !== static::DISABLED; + return $this->isEnabled !== self::DISABLED; } } diff --git a/src/Validator/Rules/LoneSchemaDefinition.php b/src/Validator/Rules/LoneSchemaDefinition.php index 4cef206..1a8da67 100644 --- a/src/Validator/Rules/LoneSchemaDefinition.php +++ b/src/Validator/Rules/LoneSchemaDefinition.php @@ -32,6 +32,7 @@ class LoneSchemaDefinition extends ValidationRule NodeKind::SCHEMA_DEFINITION => static function (SchemaDefinitionNode $node) use ($alreadyDefined, $context, &$schemaDefinitionsCount) { if ($alreadyDefined !== false) { $context->reportError(new Error('Cannot define a new schema within a schema extension.', $node)); + return; } diff --git a/src/Validator/Rules/NoUndefinedVariables.php b/src/Validator/Rules/NoUndefinedVariables.php index 5c2d4a5..c0cd22c 100644 --- a/src/Validator/Rules/NoUndefinedVariables.php +++ b/src/Validator/Rules/NoUndefinedVariables.php @@ -12,8 +12,6 @@ use GraphQL\Validator\ValidationContext; use function sprintf; /** - * Class NoUndefinedVariables - * * A GraphQL operation is only valid if all variables encountered, both directly * and via fragment spreads, are defined by that operation. */ diff --git a/src/Validator/Rules/QueryComplexity.php b/src/Validator/Rules/QueryComplexity.php index 6a3da59..85bd1ac 100644 --- a/src/Validator/Rules/QueryComplexity.php +++ b/src/Validator/Rules/QueryComplexity.php @@ -206,10 +206,12 @@ class QueryComplexity extends QuerySecurityRule $directive = Directive::includeDirective(); /** @var bool $directiveArgsIf */ $directiveArgsIf = Values::getArgumentValues($directive, $directiveNode, $variableValues)['if']; + return ! $directiveArgsIf; } $directive = Directive::skipDirective(); $directiveArgsIf = Values::getArgumentValues($directive, $directiveNode, $variableValues); + return $directiveArgsIf['if']; } } @@ -282,6 +284,6 @@ class QueryComplexity extends QuerySecurityRule protected function isEnabled() { - return $this->getMaxQueryComplexity() !== static::DISABLED; + return $this->getMaxQueryComplexity() !== self::DISABLED; } } diff --git a/src/Validator/Rules/QueryDepth.php b/src/Validator/Rules/QueryDepth.php index 2f5c9c8..6dd9168 100644 --- a/src/Validator/Rules/QueryDepth.php +++ b/src/Validator/Rules/QueryDepth.php @@ -113,6 +113,6 @@ class QueryDepth extends QuerySecurityRule protected function isEnabled() { - return $this->getMaxQueryDepth() !== static::DISABLED; + return $this->getMaxQueryDepth() !== self::DISABLED; } } diff --git a/src/Validator/Rules/ValuesOfCorrectType.php b/src/Validator/Rules/ValuesOfCorrectType.php index ad2468e..4e8199b 100644 --- a/src/Validator/Rules/ValuesOfCorrectType.php +++ b/src/Validator/Rules/ValuesOfCorrectType.php @@ -49,6 +49,7 @@ class ValuesOfCorrectType extends ValidationRule public function getVisitor(ValidationContext $context) { $fieldName = ''; + return [ NodeKind::FIELD => [ 'enter' => static function (FieldNode $node) use (&$fieldName) { @@ -281,6 +282,7 @@ class ValuesOfCorrectType extends ValidationRule return self::badArgumentValueMessage($typeName, $valueName, $fieldName, $arg->name, $message); } } + return self::badValueMessage($typeName, $valueName, $message); } } diff --git a/tests/Executor/MutationsTest.php b/tests/Executor/MutationsTest.php index 6671b2d..e511b70 100644 --- a/tests/Executor/MutationsTest.php +++ b/tests/Executor/MutationsTest.php @@ -59,6 +59,7 @@ class MutationsTest extends TestCase ], 'name' => 'NumberHolder', ]); + return new Schema([ 'query' => new ObjectType([ 'fields' => [ diff --git a/tests/Executor/ResolveTest.php b/tests/Executor/ResolveTest.php index 8fe4ab7..0baddef 100644 --- a/tests/Executor/ResolveTest.php +++ b/tests/Executor/ResolveTest.php @@ -16,7 +16,6 @@ use function uniqid; class ResolveTest extends TestCase { // Execute: resolve function - /** * @see it('default function accesses properties') */ diff --git a/tests/Executor/VariablesTest.php b/tests/Executor/VariablesTest.php index c2625ae..533beb5 100644 --- a/tests/Executor/VariablesTest.php +++ b/tests/Executor/VariablesTest.php @@ -355,7 +355,6 @@ class VariablesTest extends TestCase self::assertEquals($expected, $result->toArray()); } - // Describe: Handles non-nullable scalars /** diff --git a/tests/StarWarsIntrospectionTest.php b/tests/StarWarsIntrospectionTest.php index 94c2b7e..35da7da 100644 --- a/tests/StarWarsIntrospectionTest.php +++ b/tests/StarWarsIntrospectionTest.php @@ -11,7 +11,6 @@ class StarWarsIntrospectionTest extends TestCase { // Star Wars Introspection Tests // Basic Introspection - /** * @see it('Allows querying the schema for types') */ diff --git a/tests/StarWarsValidationTest.php b/tests/StarWarsValidationTest.php index 7e736c1..cdee2e3 100644 --- a/tests/StarWarsValidationTest.php +++ b/tests/StarWarsValidationTest.php @@ -12,7 +12,6 @@ class StarWarsValidationTest extends TestCase { // Star Wars Validation Tests // Basic Queries - /** * @see it('Validates a complex but valid query') */ diff --git a/tests/Utils/BuildSchemaTest.php b/tests/Utils/BuildSchemaTest.php index dfdf98a..e8e3280 100644 --- a/tests/Utils/BuildSchemaTest.php +++ b/tests/Utils/BuildSchemaTest.php @@ -24,7 +24,6 @@ use function count; class BuildSchemaTest extends TestCase { // Describe: Schema Builder - /** * @see it('can use built schema for limited execution') */ diff --git a/tests/Utils/SchemaExtenderTest.php b/tests/Utils/SchemaExtenderTest.php index bc9842d..341a381 100644 --- a/tests/Utils/SchemaExtenderTest.php +++ b/tests/Utils/SchemaExtenderTest.php @@ -198,6 +198,7 @@ class SchemaExtenderTest extends TestCase preg_match('/^[ \t]*/', $trimmedStr, $indentMatch); $indent = $indentMatch[0]; + return preg_replace('/^' . $indent . '/m', '', $trimmedStr); } @@ -210,6 +211,7 @@ class SchemaExtenderTest extends TestCase $ast = Parser::parse($sdl); $extendedSchema = SchemaExtender::extend($this->testSchema, $ast, $options); self::assertEquals(SchemaPrinter::doPrint($this->testSchema), $originalPrint); + return $extendedSchema; } @@ -1250,7 +1252,6 @@ class SchemaExtenderTest extends TestCase self::assertEquals('new directive', $newDirective->description); } - /** * @see it('may extend directives with new complex directive') */ @@ -1735,7 +1736,6 @@ class SchemaExtenderTest extends TestCase self::assertEquals($queryType->name, 'Foo'); } - /** * @see it('adds new root types via schema extension') */ @@ -1875,7 +1875,6 @@ class SchemaExtenderTest extends TestCase } } - /** * @see it('does not allow defining a root operation type twice') */ @@ -1964,7 +1963,6 @@ extend type Query { self::assertSame(['data' => ['hello' => 'Hello World!']], $result->toArray()); } - /** * @see https://github.com/webonyx/graphql-php/issues/180 */ diff --git a/tests/Utils/SchemaPrinterTest.php b/tests/Utils/SchemaPrinterTest.php index e014e6b..afc851b 100644 --- a/tests/Utils/SchemaPrinterTest.php +++ b/tests/Utils/SchemaPrinterTest.php @@ -21,7 +21,6 @@ use PHPUnit\Framework\TestCase; class SchemaPrinterTest extends TestCase { // Describe: Type System Printer - /** * @see it('Prints String Field') */ diff --git a/tests/Validator/ValuesOfCorrectTypeTest.php b/tests/Validator/ValuesOfCorrectTypeTest.php index a174808..ac92708 100644 --- a/tests/Validator/ValuesOfCorrectTypeTest.php +++ b/tests/Validator/ValuesOfCorrectTypeTest.php @@ -1135,7 +1135,6 @@ class ValuesOfCorrectTypeTest extends ValidatorTestCase ); } - // DESCRIBE: Valid input object value /**