diff --git a/docs/data-fetching.md b/docs/data-fetching.md index 4bc0cfb..9b6f8e7 100644 --- a/docs/data-fetching.md +++ b/docs/data-fetching.md @@ -118,7 +118,9 @@ function defaultFieldResolver($source, $args, $context, \GraphQL\Type\Definition } } - return $property instanceof Closure ? $property($source, $args, $context, $info) : $property; + return $property instanceof Closure + ? $property($source, $args, $context, $info) + : $property; } ``` diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 30ccad4..db23e50 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -182,6 +182,8 @@ class Executor } } - return $property instanceof Closure ? $property($source, $args, $context, $info) : $property; + return $property instanceof Closure + ? $property($source, $args, $context, $info) + : $property; } } diff --git a/src/Executor/ReferenceExecutor.php b/src/Executor/ReferenceExecutor.php index 6e35f7c..08911e4 100644 --- a/src/Executor/ReferenceExecutor.php +++ b/src/Executor/ReferenceExecutor.php @@ -252,9 +252,9 @@ class ReferenceExecutor implements ExecutorImplementation // // Similar to completeValueCatchingError. try { - $result = $operation->operation === 'mutation' ? - $this->executeFieldsSerially($type, $rootValue, $path, $fields) : - $this->executeFields($type, $rootValue, $path, $fields); + $result = $operation->operation === 'mutation' + ? $this->executeFieldsSerially($type, $rootValue, $path, $fields) + : $this->executeFields($type, $rootValue, $path, $fields); if ($this->isPromise($result)) { return $result->then( null, diff --git a/src/Executor/Values.php b/src/Executor/Values.php index 82e26c8..e80f868 100644 --- a/src/Executor/Values.php +++ b/src/Executor/Values.php @@ -273,6 +273,7 @@ class Values return $error->getMessage(); }, $errors - ) : []; + ) + : []; } } diff --git a/src/Language/Parser.php b/src/Language/Parser.php index a0c123f..2a68ffa 100644 --- a/src/Language/Parser.php +++ b/src/Language/Parser.php @@ -512,15 +512,15 @@ class Parser */ private function parseVariableDefinitions() { - return $this->peek(Token::PAREN_L) ? - $this->many( + return $this->peek(Token::PAREN_L) + ? $this->many( Token::PAREN_L, function () { return $this->parseVariableDefinition(); }, Token::PAREN_R - ) : - new NodeList([]); + ) + : new NodeList([]); } /** @@ -592,9 +592,9 @@ class Parser */ private function parseSelection() { - return $this->peek(Token::SPREAD) ? - $this->parseFragment() : - $this->parseField(); + return $this->peek(Token::SPREAD) + ? $this->parseFragment() + : $this->parseField(); } /** @@ -634,17 +634,17 @@ class Parser */ private function parseArguments($isConst) { - $parseFn = $isConst ? - function () { + $parseFn = $isConst + ? function () { return $this->parseConstArgument(); - } : - function () { + } + : function () { return $this->parseArgument(); }; - return $this->peek(Token::PAREN_L) ? - $this->many(Token::PAREN_L, $parseFn, Token::PAREN_R) : - new NodeList([]); + return $this->peek(Token::PAREN_L) + ? $this->many(Token::PAREN_L, $parseFn, Token::PAREN_R) + : new NodeList([]); } /** @@ -1208,8 +1208,8 @@ class Parser do { $types[] = $this->parseNamedType(); } while ($this->skip(Token::AMP) || - // Legacy support for the SDL? - (! empty($this->lexer->options['allowLegacySDLImplementsInterfaces']) && $this->peek(Token::NAME)) + // Legacy support for the SDL? + (! empty($this->lexer->options['allowLegacySDLImplementsInterfaces']) && $this->peek(Token::NAME)) ); } @@ -1545,7 +1545,8 @@ class Parser Token::BRACE_L, [$this, 'parseOperationTypeDefinition'], Token::BRACE_R - ) : []; + ) + : []; if (count($directives) === 0 && count($operationTypes) === 0) { $this->unexpected(); } diff --git a/src/Language/Visitor.php b/src/Language/Visitor.php index 45f8fff..43c59ed 100644 --- a/src/Language/Visitor.php +++ b/src/Language/Visitor.php @@ -251,8 +251,18 @@ class Visitor $inArray = $stack['inArray']; $stack = $stack['prev']; } else { - $key = $parent !== null ? ($inArray ? $index : $keys[$index]) : $UNDEFINED; - $node = $parent !== null ? ($parent instanceof NodeList || is_array($parent) ? $parent[$key] : $parent->{$key}) : $newRoot; + $key = $parent !== null + ? ($inArray + ? $index + : $keys[$index] + ) + : $UNDEFINED; + $node = $parent !== null + ? ($parent instanceof NodeList || is_array($parent) + ? $parent[$key] + : $parent->{$key} + ) + : $newRoot; if ($node === null || $node === $UNDEFINED) { continue; } diff --git a/src/Server/Helper.php b/src/Server/Helper.php index ff62b2b..8816f9f 100644 --- a/src/Server/Helper.php +++ b/src/Server/Helper.php @@ -73,10 +73,14 @@ class Helper } if (stripos($contentType, 'application/graphql') !== false) { - $rawBody = $readRawBodyFn ? $readRawBodyFn() : $this->readRawBody(); + $rawBody = $readRawBodyFn + ? $readRawBodyFn() + : $this->readRawBody(); $bodyParams = ['query' => $rawBody ?: '']; } elseif (stripos($contentType, 'application/json') !== false) { - $rawBody = $readRawBodyFn ? $readRawBodyFn() : $this->readRawBody(); + $rawBody = $readRawBodyFn ? + $readRawBodyFn() + : $this->readRawBody(); $bodyParams = json_decode($rawBody ?: '', true); if (json_last_error()) { @@ -272,7 +276,9 @@ class Helper ); } - $doc = $op->queryId ? $this->loadPersistedQuery($config, $op) : $op->query; + $doc = $op->queryId + ? $this->loadPersistedQuery($config, $op) + : $op->query; if (! $doc instanceof DocumentNode) { $doc = Parser::parse($doc); diff --git a/src/Type/Definition/InputObjectType.php b/src/Type/Definition/InputObjectType.php index c921dda..e31b998 100644 --- a/src/Type/Definition/InputObjectType.php +++ b/src/Type/Definition/InputObjectType.php @@ -69,7 +69,9 @@ class InputObjectType extends Type implements InputType, NullableType, NamedType if ($this->fields === null) { $this->fields = []; $fields = $this->config['fields'] ?? []; - $fields = is_callable($fields) ? call_user_func($fields) : $fields; + $fields = is_callable($fields) + ? call_user_func($fields) + : $fields; if (! is_array($fields)) { throw new InvariantViolation( diff --git a/src/Type/Definition/ListOfType.php b/src/Type/Definition/ListOfType.php index eb8200d..e81db88 100644 --- a/src/Type/Definition/ListOfType.php +++ b/src/Type/Definition/ListOfType.php @@ -31,6 +31,8 @@ class ListOfType extends Type implements WrappingType, OutputType, NullableType, { $type = $this->ofType; - return $recurse && $type instanceof WrappingType ? $type->getWrappedType($recurse) : $type; + return $recurse && $type instanceof WrappingType + ? $type->getWrappedType($recurse) + : $type; } } diff --git a/src/Type/Definition/NonNull.php b/src/Type/Definition/NonNull.php index 6799523..4b6fa48 100644 --- a/src/Type/Definition/NonNull.php +++ b/src/Type/Definition/NonNull.php @@ -66,6 +66,8 @@ class NonNull extends Type implements WrappingType, OutputType, InputType { $type = $this->ofType; - return $recurse && $type instanceof WrappingType ? $type->getWrappedType($recurse) : $type; + return $recurse && $type instanceof WrappingType + ? $type->getWrappedType($recurse) + : $type; } } diff --git a/src/Type/Definition/ObjectType.php b/src/Type/Definition/ObjectType.php index 532a9b0..327699a 100644 --- a/src/Type/Definition/ObjectType.php +++ b/src/Type/Definition/ObjectType.php @@ -185,7 +185,9 @@ class ObjectType extends Type implements OutputType, CompositeType, NullableType { if ($this->interfaces === null) { $interfaces = $this->config['interfaces'] ?? []; - $interfaces = is_callable($interfaces) ? call_user_func($interfaces) : $interfaces; + $interfaces = is_callable($interfaces) + ? call_user_func($interfaces) + : $interfaces; if ($interfaces !== null && ! is_array($interfaces)) { throw new InvariantViolation( @@ -207,12 +209,14 @@ class ObjectType extends Type implements OutputType, CompositeType, NullableType */ public function isTypeOf($value, $context, ResolveInfo $info) { - return isset($this->config['isTypeOf']) ? call_user_func( - $this->config['isTypeOf'], - $value, - $context, - $info - ) : null; + return isset($this->config['isTypeOf']) + ? call_user_func( + $this->config['isTypeOf'], + $value, + $context, + $info + ) + : null; } /** diff --git a/src/Type/Definition/Type.php b/src/Type/Definition/Type.php index 69faa1c..65da9e7 100644 --- a/src/Type/Definition/Type.php +++ b/src/Type/Definition/Type.php @@ -345,7 +345,9 @@ abstract class Type implements JsonSerializable */ public static function getNullableType($type) { - return $type instanceof NonNull ? $type->getWrappedType() : $type; + return $type instanceof NonNull + ? $type->getWrappedType() + : $type; } /** diff --git a/src/Type/Introspection.php b/src/Type/Introspection.php index f0cacee..3943b3e 100644 --- a/src/Type/Introspection.php +++ b/src/Type/Introspection.php @@ -488,7 +488,9 @@ EOD; 'type' => [ 'type' => Type::nonNull(self::_type()), 'resolve' => static function ($value) { - return method_exists($value, 'getType') ? $value->getType() : $value->type; + return method_exists($value, 'getType') + ? $value->getType() + : $value->type; }, ], 'defaultValue' => [ diff --git a/src/Type/SchemaValidationContext.php b/src/Type/SchemaValidationContext.php index 5e52164..a663018 100644 --- a/src/Type/SchemaValidationContext.php +++ b/src/Type/SchemaValidationContext.php @@ -768,8 +768,9 @@ class SchemaValidationContext ); } - return $union->astNode ? - $union->astNode->types : null; + return $union->astNode + ? $union->astNode->types + : null; } private function validateEnumValues(EnumType $enumType) @@ -824,8 +825,9 @@ class SchemaValidationContext ); } - return $enum->astNode ? - $enum->astNode->values : null; + return $enum->astNode + ? $enum->astNode->values + : null; } private function validateInputFields(InputObjectType $inputObj) diff --git a/src/Utils/ASTDefinitionBuilder.php b/src/Utils/ASTDefinitionBuilder.php index b743213..7cd96d0 100644 --- a/src/Utils/ASTDefinitionBuilder.php +++ b/src/Utils/ASTDefinitionBuilder.php @@ -394,8 +394,8 @@ class ASTDefinitionBuilder function ($typeNode) { return $this->buildType($typeNode); } - ) : - [], + ) + : [], 'astNode' => $def, ]); } diff --git a/src/Utils/SchemaExtender.php b/src/Utils/SchemaExtender.php index 4fefc61..6188beb 100644 --- a/src/Utils/SchemaExtender.php +++ b/src/Utils/SchemaExtender.php @@ -609,7 +609,9 @@ class SchemaExtender } $schemaExtensionASTNodes = count($schemaExtensions) > 0 - ? ($schema->extensionASTNodes ? array_merge($schema->extensionASTNodes, $schemaExtensions) : $schemaExtensions) + ? ($schema->extensionASTNodes + ? array_merge($schema->extensionASTNodes, $schemaExtensions) + : $schemaExtensions) : $schema->extensionASTNodes; $types = array_merge( diff --git a/src/Utils/SchemaPrinter.php b/src/Utils/SchemaPrinter.php index 9e9e1ca..a45c99c 100644 --- a/src/Utils/SchemaPrinter.php +++ b/src/Utils/SchemaPrinter.php @@ -353,8 +353,8 @@ class SchemaPrinter private static function printObject(ObjectType $type, array $options) : string { $interfaces = $type->getInterfaces(); - $implementedInterfaces = ! empty($interfaces) ? - ' implements ' . implode( + $implementedInterfaces = ! empty($interfaces) + ? ' implements ' . implode( ' & ', array_map( static function ($i) { @@ -362,7 +362,8 @@ class SchemaPrinter }, $interfaces ) - ) : ''; + ) + : ''; return self::printDescription($options, $type) . sprintf("type %s%s {\n%s\n}", $type->name, $implementedInterfaces, self::printFields($options, $type)); diff --git a/src/Utils/TypeInfo.php b/src/Utils/TypeInfo.php index 13892fc..8468407 100644 --- a/src/Utils/TypeInfo.php +++ b/src/Utils/TypeInfo.php @@ -302,10 +302,12 @@ class TypeInfo case $node instanceof InlineFragmentNode: case $node instanceof FragmentDefinitionNode: $typeConditionNode = $node->typeCondition; - $outputType = $typeConditionNode ? self::typeFromAST( - $schema, - $typeConditionNode - ) : Type::getNamedType($this->getType()); + $outputType = $typeConditionNode + ? self::typeFromAST( + $schema, + $typeConditionNode + ) + : Type::getNamedType($this->getType()); $this->typeStack[] = Type::isOutputType($outputType) ? $outputType : null; break; diff --git a/src/Validator/Rules/LoneSchemaDefinition.php b/src/Validator/Rules/LoneSchemaDefinition.php index 1a8da67..72e5832 100644 --- a/src/Validator/Rules/LoneSchemaDefinition.php +++ b/src/Validator/Rules/LoneSchemaDefinition.php @@ -19,12 +19,14 @@ class LoneSchemaDefinition extends ValidationRule public function getVisitor(ValidationContext $context) { $oldSchema = $context->getSchema(); - $alreadyDefined = $oldSchema !== null ? ( - $oldSchema->getAstNode() || - $oldSchema->getQueryType() || - $oldSchema->getMutationType() || - $oldSchema->getSubscriptionType() - ) : false; + $alreadyDefined = $oldSchema !== null + ? ( + $oldSchema->getAstNode() || + $oldSchema->getQueryType() || + $oldSchema->getMutationType() || + $oldSchema->getSubscriptionType() + ) + : false; $schemaDefinitionsCount = 0; diff --git a/src/Validator/Rules/OverlappingFieldsCanBeMerged.php b/src/Validator/Rules/OverlappingFieldsCanBeMerged.php index 8dfa7f1..efd9038 100644 --- a/src/Validator/Rules/OverlappingFieldsCanBeMerged.php +++ b/src/Validator/Rules/OverlappingFieldsCanBeMerged.php @@ -473,24 +473,24 @@ class OverlappingFieldsCanBeMerged extends ValidationRule private function doTypesConflict(OutputType $type1, OutputType $type2) { if ($type1 instanceof ListOfType) { - return $type2 instanceof ListOfType ? - $this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) : - true; + return $type2 instanceof ListOfType + ? $this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) + : true; } if ($type2 instanceof ListOfType) { - return $type1 instanceof ListOfType ? - $this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) : - true; + return $type1 instanceof ListOfType + ? $this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) + : true; } if ($type1 instanceof NonNull) { - return $type2 instanceof NonNull ? - $this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) : - true; + return $type2 instanceof NonNull + ? $this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) + : true; } if ($type2 instanceof NonNull) { - return $type1 instanceof NonNull ? - $this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) : - true; + return $type1 instanceof NonNull + ? $this->doTypesConflict($type1->getWrappedType(), $type2->getWrappedType()) + : true; } if (Type::isLeafType($type1) || Type::isLeafType($type2)) { return $type1 !== $type2; diff --git a/src/Validator/Rules/ProvidedRequiredArgumentsOnDirectives.php b/src/Validator/Rules/ProvidedRequiredArgumentsOnDirectives.php index 8750711..080d53e 100644 --- a/src/Validator/Rules/ProvidedRequiredArgumentsOnDirectives.php +++ b/src/Validator/Rules/ProvidedRequiredArgumentsOnDirectives.php @@ -66,13 +66,15 @@ class ProvidedRequiredArgumentsOnDirectives extends ValidationRule } $requiredArgsMap[$def->name->value] = Utils::keyMap( - $arguments ? array_filter($arguments, static function (Node $argument) : bool { - return $argument instanceof NonNullTypeNode && - ( - ! isset($argument->defaultValue) || - $argument->defaultValue === null - ); - }) : [], + $arguments + ? array_filter($arguments, static function (Node $argument) : bool { + return $argument instanceof NonNullTypeNode && + ( + ! isset($argument->defaultValue) || + $argument->defaultValue === null + ); + }) + : [], static function (NamedTypeNode $argument) : string { return $argument->name->value; } diff --git a/tests/Language/VisitorTest.php b/tests/Language/VisitorTest.php index b04b4db..0a2c6b3 100644 --- a/tests/Language/VisitorTest.php +++ b/tests/Language/VisitorTest.php @@ -70,7 +70,12 @@ class VisitorTest extends ValidatorTestCase /** @var Node $node */ [$node, $key, $parent, $path, $ancestors] = $args; - $parentArray = $parent && ! is_array($parent) ? ($parent instanceof NodeList ? iterator_to_array($parent) : $parent->toArray()) : $parent; + $parentArray = $parent && ! is_array($parent) + ? ($parent instanceof NodeList + ? iterator_to_array($parent) + : $parent->toArray() + ) + : $parent; self::assertInstanceOf(Node::class, $node); self::assertContains($node->kind, array_keys(NodeKind::$classMap)); @@ -114,7 +119,9 @@ class VisitorTest extends ValidatorTestCase { $result = $ast; foreach ($path as $key) { - $resultArray = $result instanceof NodeList ? iterator_to_array($result) : $result->toArray(); + $resultArray = $result instanceof NodeList + ? iterator_to_array($result) + : $result->toArray(); self::assertArrayHasKey($key, $resultArray); $result = $resultArray[$key]; } diff --git a/tests/Utils/SchemaExtenderTest.php b/tests/Utils/SchemaExtenderTest.php index 341a381..03529a4 100644 --- a/tests/Utils/SchemaExtenderTest.php +++ b/tests/Utils/SchemaExtenderTest.php @@ -219,7 +219,9 @@ class SchemaExtenderTest extends TestCase { $ast = Parser::parse(SchemaPrinter::doPrint($extendedSchema)); $ast->definitions = array_values(array_filter( - $ast->definitions instanceof NodeList ? iterator_to_array($ast->definitions->getIterator()) : $ast->definitions, + $ast->definitions instanceof NodeList + ? iterator_to_array($ast->definitions->getIterator()) + : $ast->definitions, function (Node $node) : bool { return ! in_array(Printer::doPrint($node), $this->testSchemaDefinitions, true); } diff --git a/tools/gendocs.php b/tools/gendocs.php index d28b0c9..7f74842 100644 --- a/tools/gendocs.php +++ b/tools/gendocs.php @@ -40,7 +40,9 @@ function renderClassMethod(ReflectionMethod $method) { $def = $type . '$' . $p->getName(); if ($p->isDefaultValueAvailable()) { - $val = $p->isDefaultValueConstant() ? $p->getDefaultValueConstantName() : $p->getDefaultValue(); + $val = $p->isDefaultValueConstant() + ? $p->getDefaultValueConstantName() + : $p->getDefaultValue(); $def .= " = " . Utils::printSafeJson($val); }