diff --git a/src/Executor/ReferenceExecutor.php b/src/Executor/ReferenceExecutor.php index 5c0353b..9fbafe3 100644 --- a/src/Executor/ReferenceExecutor.php +++ b/src/Executor/ReferenceExecutor.php @@ -134,16 +134,16 @@ class ReferenceExecutor implements ExecutorImplementation ) { $errors = []; $fragments = []; - /** @var OperationDefinitionNode $operation */ + /** @var OperationDefinitionNode|null $operation */ $operation = null; $hasMultipleAssumedOperations = false; foreach ($documentNode->definitions as $definition) { switch (true) { case $definition instanceof OperationDefinitionNode: - if (! $operationName && $operation) { + if ($operationName === null && $operation !== null) { $hasMultipleAssumedOperations = true; } - if (! $operationName || + if ($operationName === null || (isset($definition->name) && $definition->name->value === $operationName)) { $operation = $definition; } @@ -154,10 +154,10 @@ class ReferenceExecutor implements ExecutorImplementation } } if ($operation === null) { - if ($operationName) { - $errors[] = new Error(sprintf('Unknown operation named "%s".', $operationName)); - } else { + if ($operationName === null) { $errors[] = new Error('Must provide an operation.'); + } else { + $errors[] = new Error(sprintf('Unknown operation named "%s".', $operationName)); } } elseif ($hasMultipleAssumedOperations) { $errors[] = new Error( @@ -286,7 +286,7 @@ class ReferenceExecutor implements ExecutorImplementation switch ($operation->operation) { case 'query': $queryType = $schema->getQueryType(); - if (! $queryType) { + if ($queryType === null) { throw new Error( 'Schema does not define the required query root type.', [$operation] @@ -296,7 +296,7 @@ class ReferenceExecutor implements ExecutorImplementation return $queryType; case 'mutation': $mutationType = $schema->getMutationType(); - if (! $mutationType) { + if ($mutationType === null) { throw new Error( 'Schema is not configured for mutations.', [$operation] @@ -306,7 +306,7 @@ class ReferenceExecutor implements ExecutorImplementation return $mutationType; case 'subscription': $subscriptionType = $schema->getSubscriptionType(); - if (! $subscriptionType) { + if ($subscriptionType === null) { throw new Error( 'Schema is not configured for subscriptions.', [$operation] @@ -375,7 +375,7 @@ class ReferenceExecutor implements ExecutorImplementation $visitedFragmentNames[$fragName] = true; /** @var FragmentDefinitionNode|null $fragment */ $fragment = $exeContext->fragments[$fragName] ?? null; - if (! $fragment || ! $this->doesFragmentConditionMatch($fragment, $runtimeType)) { + if ($fragment === null || ! $this->doesFragmentConditionMatch($fragment, $runtimeType)) { break; } $this->collectFields( @@ -396,10 +396,8 @@ class ReferenceExecutor implements ExecutorImplementation * directives, where @skip has higher precedence than @include. * * @param FragmentSpreadNode|FieldNode|InlineFragmentNode $node - * - * @return bool */ - private function shouldIncludeNode($node) + private function shouldIncludeNode($node) : bool { $variableValues = $this->exeContext->variableValues; $skipDirective = Directive::skipDirective(); @@ -423,12 +421,10 @@ class ReferenceExecutor implements ExecutorImplementation /** * Implements the logic to compute the key of a given fields entry - * - * @return string */ - private static function getFieldEntryKey(FieldNode $node) + private static function getFieldEntryKey(FieldNode $node) : string { - return $node->alias ? $node->alias->value : $node->name->value; + return $node->alias === null ? $node->name->value : $node->alias->value; } /** @@ -480,7 +476,7 @@ class ReferenceExecutor implements ExecutorImplementation return $results; } $promise = $this->getPromise($result); - if ($promise) { + if ($promise !== null) { return $promise->then(static function ($resolvedResult) use ($responseName, $results) { $results[$responseName] = $resolvedResult; @@ -520,7 +516,7 @@ class ReferenceExecutor implements ExecutorImplementation $fieldNode = $fieldNodes[0]; $fieldName = $fieldNode->name->value; $fieldDef = $this->getFieldDef($exeContext->schema, $parentType, $fieldName); - if (! $fieldDef) { + if ($fieldDef === null) { return self::$UNDEFINED; } $returnType = $fieldDef->getType(); @@ -578,12 +574,8 @@ class ReferenceExecutor implements ExecutorImplementation * are allowed, like on a Union. __schema could get automatically * added to the query type, but that would require mutating type * definitions, which would cause issues. - * - * @param string $fieldName - * - * @return FieldDefinition */ - private function getFieldDef(Schema $schema, ObjectType $parentType, $fieldName) + private function getFieldDef(Schema $schema, ObjectType $parentType, string $fieldName) : ?FieldDefinition { static $schemaMetaFieldDef, $typeMetaFieldDef, $typeNameMetaFieldDef; $schemaMetaFieldDef = $schemaMetaFieldDef ?: Introspection::schemaMetaFieldDef(); @@ -677,7 +669,7 @@ class ReferenceExecutor implements ExecutorImplementation $result ); $promise = $this->getPromise($completed); - if ($promise) { + if ($promise !== null) { return $promise->then( null, function ($error) use ($exeContext) { @@ -726,7 +718,7 @@ class ReferenceExecutor implements ExecutorImplementation $result ); $promise = $this->getPromise($completed); - if ($promise) { + if ($promise !== null) { return $promise->then( null, function ($error) use ($fieldNodes, $path) { @@ -786,7 +778,7 @@ class ReferenceExecutor implements ExecutorImplementation ) { $promise = $this->getPromise($result); // If result is a Promise, apply-lift over completeValue. - if ($promise) { + if ($promise !== null) { return $promise->then(function (&$resolved) use ($returnType, $fieldNodes, $info, $path) { return $this->completeValue($returnType, $fieldNodes, $info, $path, $resolved); }); @@ -824,7 +816,7 @@ class ReferenceExecutor implements ExecutorImplementation // instance than `resolveType` or $field->getType() or $arg->getType() if ($returnType !== $this->exeContext->schema->getType($returnType->name)) { $hint = ''; - if ($this->exeContext->schema->getConfig()->typeLoader) { + if ($this->exeContext->schema->getConfig()->typeLoader !== null) { $hint = sprintf( 'Make sure that type loader returns the same instance as defined in %s.%s', $info->parentType, @@ -904,7 +896,7 @@ class ReferenceExecutor implements ExecutorImplementation * @param mixed[] $values * @param Promise|mixed|null $initialValue * - * @return mixed[] + * @return mixed */ private function promiseReduce(array $values, callable $callback, $initialValue) { @@ -912,7 +904,7 @@ class ReferenceExecutor implements ExecutorImplementation $values, function ($previous, $value) use ($callback) { $promise = $this->getPromise($previous); - if ($promise) { + if ($promise !== null) { return $promise->then(static function ($resolved) use ($callback, $value) { return $callback($resolved, $value); }); @@ -950,7 +942,7 @@ class ReferenceExecutor implements ExecutorImplementation $fieldPath = $path; $fieldPath[] = $i++; $completedItem = $this->completeValueCatchingError($itemType, $fieldNodes, $info, $fieldPath, $item); - if (! $containsPromise && $this->getPromise($completedItem)) { + if (! $containsPromise && $this->getPromise($completedItem) !== null) { $containsPromise = true; } $completedItems[] = $completedItem; @@ -1007,7 +999,7 @@ class ReferenceExecutor implements ExecutorImplementation $runtimeType = self::defaultTypeResolver($result, $exeContext->contextValue, $info, $returnType); } $promise = $this->getPromise($runtimeType); - if ($promise) { + if ($promise !== null) { return $promise->then(function ($resolvedRuntimeType) use ( $returnType, $fieldNodes, @@ -1069,7 +1061,8 @@ class ReferenceExecutor implements ExecutorImplementation ) { return $value['__typename']; } - if ($abstractType instanceof InterfaceType && $info->schema->getConfig()->typeLoader) { + + if ($abstractType instanceof InterfaceType && $info->schema->getConfig()->typeLoader !== null) { Warning::warnOnce( sprintf( 'GraphQL Interface Type `%s` returned `null` from its `resolveType` function ' . @@ -1091,7 +1084,7 @@ class ReferenceExecutor implements ExecutorImplementation continue; } $promise = $this->getPromise($isTypeOfResult); - if ($promise) { + if ($promise !== null) { $promisedIsTypeOfResults[$index] = $promise; } elseif ($isTypeOfResult) { return $type; @@ -1132,7 +1125,7 @@ class ReferenceExecutor implements ExecutorImplementation $isTypeOf = $returnType->isTypeOf($result, $this->exeContext->contextValue, $info); if ($isTypeOf !== null) { $promise = $this->getPromise($isTypeOf); - if ($promise) { + if ($promise !== null) { return $promise->then(function ($isTypeOfResult) use ( $returnType, $fieldNodes, @@ -1248,7 +1241,7 @@ class ReferenceExecutor implements ExecutorImplementation if ($result === self::$UNDEFINED) { continue; } - if (! $containsPromise && $this->getPromise($result)) { + if (! $containsPromise && $this->getPromise($result) !== null) { $containsPromise = true; } $finalResults[$responseName] = $result; @@ -1310,7 +1303,6 @@ class ReferenceExecutor implements ExecutorImplementation /** * @param string|ObjectType|null $runtimeTypeOrName - * @param FieldNode[] $fieldNodes * @param mixed $result * * @return ObjectType diff --git a/src/Type/Definition/Directive.php b/src/Type/Definition/Directive.php index 3ad4b8a..f77075c 100644 --- a/src/Type/Definition/Directive.php +++ b/src/Type/Definition/Directive.php @@ -24,7 +24,7 @@ class Directive public const REASON_ARGUMENT_NAME = 'reason'; /** @var Directive[] */ - public static $internalDirectives; + public static $internalDirectives = []; // Schema Definitions