diff --git a/.php_cs.dist b/.php_cs.dist index 0bf4d3950..11a8cb6f3 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -10,6 +10,8 @@ return PhpCsFixer\Config::create() ->setRules( [ '@Symfony' => true, + '@PHP71Migration' => true, + '@PHP74Migration:risky' => true, 'ordered_imports' => ['imports_order' => ['class', 'function', 'const']], 'general_phpdoc_annotation_remove' => ['author', 'category', 'copyright', 'created', 'license', 'package', 'since', 'subpackage', 'version'], 'fully_qualified_strict_types' => true, @@ -19,7 +21,9 @@ return PhpCsFixer\Config::create() 'global_namespace_import' => ['import_functions' => true, 'import_classes' => true, 'import_constants' => true], 'phpdoc_summary' => false, 'hash_to_slash_comment' => false, - 'single_line_comment_style' => false + 'single_line_comment_style' => false, + 'phpdoc_no_alias_tag' => ['type' => 'var'], + 'no_mixed_echo_print' => ['use' => 'echo'], ] ) ->setFinder($finder) diff --git a/UPGRADE.md b/UPGRADE.md index f2cfe56fb..a6fc9dc04 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -12,6 +12,8 @@ UPGRADE FROM 0.13 to 0.14 - [Replace `overblog_graphql.global_variable` tag](#replace-overblog_graphqlglobal_variable-tag) - [Replace `resolver` expression function](#replace-resolver-expression-function) - [Rename `ResolverInterface` to `QueryInterface`](#rename-resolverinterface-to-queryinterface) +- [Remove Argument deprecated method](#remove-argument-deprecated-method) +- [Remove ConnectionBuilder deprecated class](#remove-connectionbuilder-deprecated-class) ### Customize the cursor encoder of the edges of a connection @@ -199,6 +201,15 @@ Example: } ``` +### Remove Argument deprecated method + +Method `Overblog\GraphQLBundle\Definition\Argument::getRawArguments` is replaced by +`Overblog\GraphQLBundle\Definition\Argument::getArrayCopy`. + +### Remove ConnectionBuilder deprecated class + +Class `Overblog\GraphQLBundle\Relay\Connection\Output\ConnectionBuilder` is replaced by +`Overblog\GraphQLBundle\Relay\Connection\ConnectionBuilder`. UPGRADE FROM 0.12 to 0.13 ======================= diff --git a/composer.json b/composer.json index 4c5d7e1e1..3bfdfe910 100644 --- a/composer.json +++ b/composer.json @@ -80,7 +80,7 @@ "test -f phpbench.phar || wget https://github.com/phpbench/phpbench/releases/download/1.0.0-alpha7/phpbench.phar -O phpbench.phar", "@php phpbench.phar run -l dots --ansi -vvv --report='generator: \"table\", cols: [\"benchmark\", \"subject\", \"params\", \"best\", \"mean\", \"mode\", \"worst\", \"diff\"], break: [\"benchmark\"], sort: {mean: \"asc\"}'" ], - "install-cs": "test -f php-cs-fixer.phar || wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.16.4/php-cs-fixer.phar -O php-cs-fixer.phar", + "install-cs": "test -f php-cs-fixer.phar || wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.18.7/php-cs-fixer.phar -O php-cs-fixer.phar", "fix-cs": [ "@install-cs", "@php php-cs-fixer.phar fix --diff -v --allow-risky=yes --ansi" diff --git a/src/Config/ObjectTypeDefinition.php b/src/Config/ObjectTypeDefinition.php index 25017e51f..8444b21ea 100644 --- a/src/Config/ObjectTypeDefinition.php +++ b/src/Config/ObjectTypeDefinition.php @@ -50,9 +50,7 @@ public function getDefinition(): ArrayNodeDefinition private function treatFieldsDefaultAccess(ArrayNodeDefinition $node): void { $node->validate() - ->ifTrue(function ($v) { - return array_key_exists('fieldsDefaultAccess', $v) && null !== $v['fieldsDefaultAccess']; - }) + ->ifTrue(fn ($v) => array_key_exists('fieldsDefaultAccess', $v) && null !== $v['fieldsDefaultAccess']) ->then(function ($v) { foreach ($v['fields'] as &$field) { if (array_key_exists('access', $field) && null !== $field['access']) { diff --git a/src/Config/Parser/AnnotationParser.php b/src/Config/Parser/AnnotationParser.php index f988d5411..d262a8d49 100644 --- a/src/Config/Parser/AnnotationParser.php +++ b/src/Config/Parser/AnnotationParser.php @@ -15,7 +15,7 @@ class AnnotationParser extends MetadataParser { - const METADATA_FORMAT = '@%s'; + public const METADATA_FORMAT = '@%s'; protected static ?AnnotationReader $annotationReader = null; diff --git a/src/Config/Parser/AttributeParser.php b/src/Config/Parser/AttributeParser.php index 1b0fde019..73ad4c226 100644 --- a/src/Config/Parser/AttributeParser.php +++ b/src/Config/Parser/AttributeParser.php @@ -14,7 +14,7 @@ class AttributeParser extends MetadataParser { - const METADATA_FORMAT = '#[%s]'; + public const METADATA_FORMAT = '#[%s]'; public static function getMetadatas(Reflector $reflector): array { diff --git a/src/Config/Parser/MetadataParser/MetadataParser.php b/src/Config/Parser/MetadataParser/MetadataParser.php index 3d186e4f7..a3d9007d8 100644 --- a/src/Config/Parser/MetadataParser/MetadataParser.php +++ b/src/Config/Parser/MetadataParser/MetadataParser.php @@ -44,8 +44,8 @@ abstract class MetadataParser implements PreParserInterface { - const ANNOTATION_NAMESPACE = 'Overblog\GraphQLBundle\Annotation\\'; - const METADATA_FORMAT = '%s'; + public const ANNOTATION_NAMESPACE = 'Overblog\GraphQLBundle\Annotation\\'; + public const METADATA_FORMAT = '%s'; private static ClassesTypesMap $map; private static array $typeGuessers = []; @@ -233,7 +233,7 @@ private static function classMetadatasToGQLConfiguration( if (null !== $gqlType) { if (!$gqlName) { - $gqlName = isset($classMetadata->name) ? $classMetadata->name : $reflectionClass->getShortName(); + $gqlName = !empty($classMetadata->name) ? $classMetadata->name : $reflectionClass->getShortName(); } if ($preProcess) { @@ -346,9 +346,7 @@ private static function graphQLTypeConfigFromAnnotation(ReflectionClass $reflect $buildersAnnotations = array_merge(self::getMetadataMatching($metadatas, Metadata\FieldsBuilder::class), $typeAnnotation->builders); if (!empty($buildersAnnotations)) { - $typeConfiguration['builders'] = array_map(function ($fieldsBuilderAnnotation) { - return ['builder' => $fieldsBuilderAnnotation->name, 'builderConfig' => $fieldsBuilderAnnotation->config]; - }, $buildersAnnotations); + $typeConfiguration['builders'] = array_map(fn ($fieldsBuilderAnnotation) => ['builder' => $fieldsBuilderAnnotation->name, 'builderConfig' => $fieldsBuilderAnnotation->config], $buildersAnnotations); } if (isset($typeAnnotation->isTypeOf)) { @@ -593,7 +591,7 @@ private static function getTypeFieldConfigurationFromReflector(ReflectionClass $ if (is_string($fieldMetadata->argsBuilder)) { $fieldConfiguration['argsBuilder'] = ['builder' => $fieldMetadata->argsBuilder, 'config' => []]; } elseif (is_array($fieldMetadata->argsBuilder)) { - list($builder, $builderConfig) = $fieldMetadata->argsBuilder; + [$builder, $builderConfig] = $fieldMetadata->argsBuilder; $fieldConfiguration['argsBuilder'] = ['builder' => $builder, 'config' => $builderConfig]; } else { throw new InvalidArgumentException(sprintf('The attribute "argsBuilder" on metadata %s defined on "%s" must be a string or an array where first index is the builder name and the second is the config.', static::formatMetadata($fieldMetadataName), $reflector->getName())); @@ -608,7 +606,7 @@ private static function getTypeFieldConfigurationFromReflector(ReflectionClass $ $fieldConfiguration['builder'] = $fieldMetadata->fieldBuilder; $fieldConfiguration['builderConfig'] = []; } elseif (is_array($fieldMetadata->fieldBuilder)) { - list($builder, $builderConfig) = $fieldMetadata->fieldBuilder; + [$builder, $builderConfig] = $fieldMetadata->fieldBuilder; $fieldConfiguration['builder'] = $builder; $fieldConfiguration['builderConfig'] = $builderConfig ?: []; } else { @@ -929,7 +927,7 @@ private static function guessType(ReflectionClass $reflectionClass, Reflector $r } } - throw new TypeGuessingException(join("\n", $errors)); + throw new TypeGuessingException(implode("\n", $errors)); } /** diff --git a/src/Config/Processor/InheritanceProcessor.php b/src/Config/Processor/InheritanceProcessor.php index a58feec80..634162e87 100644 --- a/src/Config/Processor/InheritanceProcessor.php +++ b/src/Config/Processor/InheritanceProcessor.php @@ -39,9 +39,7 @@ public static function process(array $configs): array private static function removedDecorators(array $configs): array { - return array_filter($configs, function ($config) { - return !isset($config['decorator']) || true !== $config['decorator']; - }); + return array_filter($configs, fn ($config) => !isset($config['decorator']) || true !== $config['decorator']); } private static function processConfigsHeirs(array $configs): array diff --git a/src/Definition/Argument.php b/src/Definition/Argument.php index 3c30bf377..2cf8fa815 100644 --- a/src/Definition/Argument.php +++ b/src/Definition/Argument.php @@ -6,9 +6,6 @@ use function array_key_exists; use function count; -use function sprintf; -use function trigger_error; -use const E_USER_DEPRECATED; class Argument implements ArgumentInterface { @@ -32,23 +29,6 @@ public function getArrayCopy(): array return $this->rawArguments; } - /** - * @deprecated This method is deprecated since 0.12 and will be removed in 0.13. You should use getArrayCopy method instead. - */ - public function getRawArguments(): array - { - @trigger_error( - sprintf( - 'This "%s" method is deprecated since 0.12 and will be removed in 0.13. You should use "%s::getArrayCopy" instead.', - __METHOD__, - __CLASS__ - ), - E_USER_DEPRECATED - ); - - return $this->getArrayCopy(); - } - /** * @param int|string $offset */ diff --git a/src/Definition/Type/CustomScalarType.php b/src/Definition/Type/CustomScalarType.php index c3e5da906..7ab46a301 100644 --- a/src/Definition/Type/CustomScalarType.php +++ b/src/Definition/Type/CustomScalarType.php @@ -19,7 +19,7 @@ public function __construct(array $config = []) $config['name'] = $config['name'] ?? uniqid('CustomScalar'); parent::__construct($config); - $this->config['scalarType'] = isset($this->config['scalarType']) ? $this->config['scalarType'] : null; + $this->config['scalarType'] = $this->config['scalarType'] ?? null; } /** diff --git a/src/DependencyInjection/Compiler/ConfigParserPass.php b/src/DependencyInjection/Compiler/ConfigParserPass.php index 2750b5baa..a391a549b 100644 --- a/src/DependencyInjection/Compiler/ConfigParserPass.php +++ b/src/DependencyInjection/Compiler/ConfigParserPass.php @@ -156,9 +156,7 @@ private function parseTypeConfigFiles(string $type, iterable $files, ContainerBu private function checkTypesDuplication(array $typeConfigs): void { $types = array_merge(...array_map('array_keys', $typeConfigs)); - $duplications = array_keys(array_filter(array_count_values($types), function ($count) { - return $count > 1; - })); + $duplications = array_keys(array_filter(array_count_values($types), fn ($count) => $count > 1)); if (!empty($duplications)) { throw new ForbiddenOverwriteException(sprintf( 'Types (%s) cannot be overwritten. See inheritance doc section for more details.', diff --git a/src/DependencyInjection/Compiler/TaggedServiceMappingPass.php b/src/DependencyInjection/Compiler/TaggedServiceMappingPass.php index 89e7c84d8..cfd63644f 100644 --- a/src/DependencyInjection/Compiler/TaggedServiceMappingPass.php +++ b/src/DependencyInjection/Compiler/TaggedServiceMappingPass.php @@ -96,9 +96,7 @@ private static function resolveAttributes(array $attributes, string $id, bool $w private function autowireSolutionImplementingContainerAwareInterface(Definition $solutionDefinition, bool $isGenerated): void { $methods = array_map( - function ($methodCall) { - return $methodCall[0]; - }, + fn ($methodCall) => $methodCall[0], $solutionDefinition->getMethodCalls() ); if ( diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 7a9396523..18a2b335c 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -270,9 +270,7 @@ private function definitionsMappingsSection(): ArrayNodeDefinition ->prototype('array') ->addDefaultsIfNotSet() ->beforeNormalization() - ->ifTrue(function ($v) { - return isset($v['type']) && is_string($v['type']); - }) + ->ifTrue(fn ($v) => isset($v['type']) && is_string($v['type'])) ->then(function ($v) { if ('yml' === $v['type']) { $v['types'] = ['yaml']; diff --git a/src/DependencyInjection/TypesConfiguration.php b/src/DependencyInjection/TypesConfiguration.php index 9999698ed..1e83f8558 100644 --- a/src/DependencyInjection/TypesConfiguration.php +++ b/src/DependencyInjection/TypesConfiguration.php @@ -57,7 +57,7 @@ public function getConfigTreeBuilder() } } - return false; + return false; }) ->thenInvalid( sprintf( diff --git a/src/ExpressionLanguage/ExpressionFunction/GraphQL/Mutation.php b/src/ExpressionLanguage/ExpressionFunction/GraphQL/Mutation.php index 808676555..78df77b79 100644 --- a/src/ExpressionLanguage/ExpressionFunction/GraphQL/Mutation.php +++ b/src/ExpressionLanguage/ExpressionFunction/GraphQL/Mutation.php @@ -15,7 +15,7 @@ public function __construct($name = self::NAME) parent::__construct( $name, function (string $alias, ...$args) { - $args = count($args) > 0 ? ', '.join(', ', $args) : ''; + $args = count($args) > 0 ? ', '.implode(', ', $args) : ''; return "$this->gqlServices->mutation({$alias}{$args})"; } diff --git a/src/ExpressionLanguage/ExpressionFunction/GraphQL/Query.php b/src/ExpressionLanguage/ExpressionFunction/GraphQL/Query.php index 40769bb5e..14f63b99e 100644 --- a/src/ExpressionLanguage/ExpressionFunction/GraphQL/Query.php +++ b/src/ExpressionLanguage/ExpressionFunction/GraphQL/Query.php @@ -15,7 +15,7 @@ public function __construct($name = self::NAME) parent::__construct( $name, function (string $alias, ...$args) { - $args = (count($args) > 0) ? (', '.join(', ', $args)) : ''; + $args = (count($args) > 0) ? (', '.implode(', ', $args)) : ''; return "$this->gqlServices->query({$alias}{$args})"; } diff --git a/src/Generator/TypeBuilder.php b/src/Generator/TypeBuilder.php index 3704a0556..9ff61ebfe 100644 --- a/src/Generator/TypeBuilder.php +++ b/src/Generator/TypeBuilder.php @@ -729,8 +729,14 @@ public function buildField(array $fieldConfig, string $fieldname) $field->addItem('useStrictAccess', false); } - if ('input-object' === $this->type && isset($c->validation)) { - $field->addItem('validation', $this->buildValidationRules($c->validation)); + if ('input-object' === $this->type) { + if (property_exists($c, 'defaultValue')) { + $field->addItem('defaultValue', $c->defaultValue); + } + + if (isset($c->validation)) { + $field->addItem('validation', $this->buildValidationRules($c->validation)); + } } return $field; @@ -770,8 +776,8 @@ public function buildArg(array $argConfig, string $argName): Collection $arg->addIfNotEmpty('description', $c->description); } - if (isset($c->defaultValue)) { - $arg->addIfNotEmpty('defaultValue', $c->defaultValue); + if (property_exists($c, 'defaultValue')) { + $arg->addItem('defaultValue', $c->defaultValue); } if (!empty($c->validation)) { diff --git a/src/Relay/Connection/ConnectionBuilder.php b/src/Relay/Connection/ConnectionBuilder.php index 3b80ddd2c..962d53d2e 100644 --- a/src/Relay/Connection/ConnectionBuilder.php +++ b/src/Relay/Connection/ConnectionBuilder.php @@ -85,9 +85,7 @@ public function connectionFromPromisedArray($dataPromise, $args = []) { $this->checkPromise($dataPromise); - return $dataPromise->then(function ($data) use ($args) { - return $this->connectionFromArray($data, $args); - }); + return $dataPromise->then(fn ($data) => $this->connectionFromArray($data, $args)); } /** @@ -189,9 +187,7 @@ public function connectionFromPromisedArraySlice($dataPromise, $args, array $met { $this->checkPromise($dataPromise); - return $dataPromise->then(function ($arraySlice) use ($args, $meta) { - return $this->connectionFromArraySlice($arraySlice, $args, $meta); - }); + return $dataPromise->then(fn ($arraySlice) => $this->connectionFromArraySlice($arraySlice, $args, $meta)); } /** @@ -199,7 +195,7 @@ public function connectionFromPromisedArraySlice($dataPromise, $args, array $met * * @param mixed $object */ - public function cursorForObjectInConnection(array $data, $object): ? string + public function cursorForObjectInConnection(array $data, $object): ?string { $offset = null; diff --git a/src/Relay/Connection/EdgeInterface.php b/src/Relay/Connection/EdgeInterface.php index 416561a1b..161fa5a4a 100644 --- a/src/Relay/Connection/EdgeInterface.php +++ b/src/Relay/Connection/EdgeInterface.php @@ -25,7 +25,7 @@ public function setNode($node): void; * * @return string */ - public function getCursor(): ? string; + public function getCursor(): ?string; /** * Set the edge cursor. diff --git a/src/Relay/Connection/Output/Connection.php b/src/Relay/Connection/Output/Connection.php index d183a461f..ad6153be3 100644 --- a/src/Relay/Connection/Output/Connection.php +++ b/src/Relay/Connection/Output/Connection.php @@ -46,7 +46,7 @@ public function setEdges(iterable $edges): void /** * {@inheritdoc} */ - public function getPageInfo(): ? PageInfoInterface + public function getPageInfo(): ?PageInfoInterface { return $this->pageInfo; } diff --git a/src/Relay/Connection/Output/ConnectionBuilder.php b/src/Relay/Connection/Output/ConnectionBuilder.php deleted file mode 100644 index 2bfca88f6..000000000 --- a/src/Relay/Connection/Output/ConnectionBuilder.php +++ /dev/null @@ -1,97 +0,0 @@ -$func(...$arguments); - } -} diff --git a/src/Relay/Connection/Output/Edge.php b/src/Relay/Connection/Output/Edge.php index ca8dd14a1..b5f842b18 100644 --- a/src/Relay/Connection/Output/Edge.php +++ b/src/Relay/Connection/Output/Edge.php @@ -43,7 +43,7 @@ public function setNode($node): void /** * {@inheritdoc} */ - public function getCursor(): ? string + public function getCursor(): ?string { return $this->cursor; } diff --git a/src/Relay/Connection/Paginator.php b/src/Relay/Connection/Paginator.php index 06e565713..d575b3ae9 100644 --- a/src/Relay/Connection/Paginator.php +++ b/src/Relay/Connection/Paginator.php @@ -68,9 +68,7 @@ public function forward(ArgumentInterface $args) if (!is_numeric($this->connectionBuilder->cursorToOffset($after)) || !$after) { $entities = call_user_func($this->fetcher, $offset, $limit ? $limit + 1 : $limit); - return $this->handleEntities($entities, function ($entities) use ($args) { - return $this->connectionBuilder->connectionFromArray($entities, $args); - }); + return $this->handleEntities($entities, fn ($entities) => $this->connectionBuilder->connectionFromArray($entities, $args)); } else { $entities = call_user_func($this->fetcher, $offset, $limit ? $limit + 2 : $limit); diff --git a/src/Relay/Node/GlobalId.php b/src/Relay/Node/GlobalId.php index e637801f4..c9371c59a 100644 --- a/src/Relay/Node/GlobalId.php +++ b/src/Relay/Node/GlobalId.php @@ -40,7 +40,7 @@ public static function fromGlobalId($globalId): array return $decodeGlobalId; } - list($decodeGlobalId['type'], $decodeGlobalId['id']) = array_pad(explode(static::SEPARATOR, $unBasedGlobalId, 2), 2, null); + [$decodeGlobalId['type'], $decodeGlobalId['id']] = array_pad(explode(static::SEPARATOR, $unBasedGlobalId, 2), 2, null); // transform empty string to null foreach ($decodeGlobalId as &$v) { $v = '' === $v ? null : $v; diff --git a/src/Resolver/AccessResolver.php b/src/Resolver/AccessResolver.php index 847d91133..17a149f61 100644 --- a/src/Resolver/AccessResolver.php +++ b/src/Resolver/AccessResolver.php @@ -40,9 +40,7 @@ public function resolve(callable $accessChecker, callable $resolveCallback, arra if ($this->isThenable($resultOrPromise)) { return $this->createPromise( $resultOrPromise, - function ($result) use ($accessChecker, $resolveArgs) { - return $this->processFilter($result, $accessChecker, $resolveArgs); - } + fn ($result) => $this->processFilter($result, $accessChecker, $resolveArgs) ); } diff --git a/src/Security/Security.php b/src/Security/Security.php index 5161ce7fc..9213a16c1 100644 --- a/src/Security/Security.php +++ b/src/Security/Security.php @@ -59,9 +59,7 @@ public function hasAnyRole(array $roles): bool { return array_reduce( $roles, - function ($isGranted, $role) { - return $isGranted || $this->isGranted($role); - }, + fn ($isGranted, $role) => $isGranted || $this->isGranted($role), false ); } diff --git a/src/Transformer/ArgumentsTransformer.php b/src/Transformer/ArgumentsTransformer.php index 148e2681b..7879ded55 100644 --- a/src/Transformer/ArgumentsTransformer.php +++ b/src/Transformer/ArgumentsTransformer.php @@ -75,9 +75,7 @@ private function populateObject(Type $type, $data, bool $multiple, ResolveInfo $ } if ($multiple) { - return array_map(function ($data) use ($type, $info) { - return $this->populateObject($type, $data, false, $info); - }, $data); + return array_map(fn ($data) => $this->populateObject($type, $data, false, $info), $data); } if ($type instanceof EnumType) { diff --git a/tests/Config/Parser/TestCase.php b/tests/Config/Parser/TestCase.php index 01ade647b..4cacf124c 100644 --- a/tests/Config/Parser/TestCase.php +++ b/tests/Config/Parser/TestCase.php @@ -35,8 +35,6 @@ protected static function cleanConfig(array $config): array } } - return array_filter($config, function ($item) { - return !is_array($item) || !empty($item); - }); + return array_filter($config, fn ($item) => !is_array($item) || !empty($item)); } } diff --git a/tests/Config/Parser/fixtures/annotations/Deprecated/DeprecatedEnum.php b/tests/Config/Parser/fixtures/annotations/Deprecated/DeprecatedEnum.php index 7bea543c2..c34a8bfc9 100644 --- a/tests/Config/Parser/fixtures/annotations/Deprecated/DeprecatedEnum.php +++ b/tests/Config/Parser/fixtures/annotations/Deprecated/DeprecatedEnum.php @@ -14,6 +14,6 @@ */ class DeprecatedEnum { - const P1 = 1; - const P2 = 2; + public const P1 = 1; + public const P2 = 2; } diff --git a/tests/Definition/ArgumentTest.php b/tests/Definition/ArgumentTest.php index 279a6d1ec..763771acd 100644 --- a/tests/Definition/ArgumentTest.php +++ b/tests/Definition/ArgumentTest.php @@ -54,14 +54,4 @@ public function testGetRawArgs(): void { $this->assertSame($this->rawArgs, $this->argument->getArrayCopy()); } - - /** - * @group legacy - * - * @expectedDeprecation This "%s" method is deprecated since 0.12 and will be removed in 0.13. You should use "%s::getArrayCopy" instead. - */ - public function testDeprecatedGetRawArgs(): void - { - $this->assertSame($this->rawArgs, $this->argument->getRawArguments()); - } } diff --git a/tests/Definition/Type/CustomScalarTypeTest.php b/tests/Definition/Type/CustomScalarTypeTest.php index 1a069a8ad..5ed87583d 100644 --- a/tests/Definition/Type/CustomScalarTypeTest.php +++ b/tests/Definition/Type/CustomScalarTypeTest.php @@ -22,16 +22,12 @@ class CustomScalarTypeTest extends TestCase public function testScalarTypeConfig(): void { $this->assertScalarTypeConfig(new YearScalarType()); - $this->assertScalarTypeConfig(function () { - return new YearScalarType(); - }); + $this->assertScalarTypeConfig(fn () => new YearScalarType()); } public function testWithoutScalarTypeConfig(): void { - $genericFunc = function ($value) { - return $value; - }; + $genericFunc = fn ($value) => $value; $type = new CustomScalarType([ 'serialize' => $genericFunc, 'parseValue' => $genericFunc, @@ -78,15 +74,11 @@ public function invalidScalarTypeProvider(): Generator yield [false, 'false']; yield [new stdClass(), 'instance of stdClass']; yield [ - function () { - return false; - }, + fn () => false, 'false', ]; yield [ - function () { - return new stdClass(); - }, + fn () => new stdClass(), 'instance of stdClass', ]; } @@ -100,15 +92,9 @@ private function assertScalarTypeConfig($scalarType): void { $type = new CustomScalarType([ 'scalarType' => $scalarType, - 'serialize' => function () { - return 'serialize'; - }, - 'parseValue' => function () { - return 'parseValue'; - }, - 'parseLiteral' => function () { - return 'parseLiteral'; - }, + 'serialize' => fn () => 'serialize', + 'parseValue' => fn () => 'parseValue', + 'parseLiteral' => fn () => 'parseLiteral', ]); $this->assertSame('50 AC', $type->serialize(50)); diff --git a/tests/EventListener/TypeDecoratorListenerTest.php b/tests/EventListener/TypeDecoratorListenerTest.php index 67a720b07..ee68200e6 100644 --- a/tests/EventListener/TypeDecoratorListenerTest.php +++ b/tests/EventListener/TypeDecoratorListenerTest.php @@ -32,9 +32,7 @@ class TypeDecoratorListenerTest extends TestCase public function testSpecialField($fieldName, Type $typeWithSpecialField, callable $fieldValueRetriever = null, $strict = true): void { if (null === $fieldValueRetriever) { - $fieldValueRetriever = function (Type $type, $fieldName) { - return $type->config[$fieldName]; - }; + $fieldValueRetriever = fn (Type $type, $fieldName) => $type->config[$fieldName]; } $expected = static function (): void { }; @@ -67,12 +65,8 @@ public function testObjectTypeFieldDecoration(): ObjectType ]; }, ]); - $barResolver = static function () { - return 'bar'; - }; - $bazResolver = static function () { - return 'baz'; - }; + $barResolver = static fn () => 'bar'; + $bazResolver = static fn () => 'baz'; $this->decorate( [$objectType->name => $objectType], @@ -105,9 +99,7 @@ public function testWrappedResolver(): void [$objectType->name => $objectType], [ $objectType->name => [ - 'bar' => function ($value, $args) { - return $args; - }, + 'bar' => fn ($value, $args) => $args, ], ] ); @@ -256,9 +248,7 @@ public function specialTypeFieldProvider(): array [ ResolverMapInterface::RESOLVE_FIELD, $objectWithResolveField, - function (ObjectType $type) { - return $type->resolveFieldFn; - }, + fn (ObjectType $type) => $type->resolveFieldFn, false, ], [ResolverMapInterface::RESOLVE_FIELD, $objectWithResolveField, null, false], diff --git a/tests/ExpressionLanguage/ExpressionLanguageTest.php b/tests/ExpressionLanguage/ExpressionLanguageTest.php index f378ac238..b483213cd 100644 --- a/tests/ExpressionLanguage/ExpressionLanguageTest.php +++ b/tests/ExpressionLanguage/ExpressionLanguageTest.php @@ -53,6 +53,6 @@ public function extractExpressionVarNamesProvider(): iterable yield ['f()', []]; yield ['a.c + b', ['a', 'b']]; yield ['(a.c) + b - d', ['a', 'b', 'd']]; - yield['a && b && c', ['a', 'b', 'c']]; + yield ['a && b && c', ['a', 'b', 'c']]; } } diff --git a/tests/ExpressionLanguage/TestCase.php b/tests/ExpressionLanguage/TestCase.php index 48b5725d4..0cd96f6f6 100644 --- a/tests/ExpressionLanguage/TestCase.php +++ b/tests/ExpressionLanguage/TestCase.php @@ -106,21 +106,13 @@ private function getCoreSecurityMock(): CoreSecurity protected function createGraphQLServices(array $services = []): GraphQLServices { $locateableServices = [ - 'typeResolver' => function () { - return $this->createMock(TypeResolver::class); - }, - 'queryResolver' => function () { - return $this->createMock(TypeResolver::class); - }, - 'mutationResolver' => function () { - return $$this->createMock(MutationResolver::class); - }, + 'typeResolver' => fn () => $this->createMock(TypeResolver::class), + 'queryResolver' => fn () => $this->createMock(TypeResolver::class), + 'mutationResolver' => fn () => $$this->createMock(MutationResolver::class), ]; foreach ($services as $id => $service) { - $locateableServices[$id] = function () use ($service) { - return $service; - }; + $locateableServices[$id] = fn () => $service; } return new GraphQLServices($locateableServices); diff --git a/tests/Functional/App/GraphQL/HelloWord/Type/QueryType.php b/tests/Functional/App/GraphQL/HelloWord/Type/QueryType.php index fba35a1e5..a868eb43d 100644 --- a/tests/Functional/App/GraphQL/HelloWord/Type/QueryType.php +++ b/tests/Functional/App/GraphQL/HelloWord/Type/QueryType.php @@ -23,9 +23,7 @@ public function __construct(QueryResolver $resolver) 'args' => [ 'message' => ['type' => Type::string()], ], - 'resolve' => function ($root, $args) use ($resolver) { - return $resolver->resolve([sprintf('%s::display', EchoQuery::class), [$args['message']]]); - }, + 'resolve' => fn ($root, $args) => $resolver->resolve([sprintf('%s::display', EchoQuery::class), [$args['message']]]), ], ], ]); diff --git a/tests/Functional/App/Resolver/Characters.php b/tests/Functional/App/Resolver/Characters.php index ead7c1494..171e79651 100644 --- a/tests/Functional/App/Resolver/Characters.php +++ b/tests/Functional/App/Resolver/Characters.php @@ -123,8 +123,6 @@ public static function resurrectZigZag(): array private static function findByType(string $type): array { - return array_filter(self::$characters, function ($character) use ($type) { - return $type === $character['type']; - }); + return array_filter(self::$characters, fn ($character) => $type === $character['type']); } } diff --git a/tests/Functional/App/Resolver/ConnectionResolver.php b/tests/Functional/App/Resolver/ConnectionResolver.php index 68fc8d4ba..64839ffa5 100644 --- a/tests/Functional/App/Resolver/ConnectionResolver.php +++ b/tests/Functional/App/Resolver/ConnectionResolver.php @@ -49,23 +49,17 @@ public function __construct(PromiseAdapter $promiseAdapter) public function friendsResolver(array $user, ArgumentInterface $args): GraphQLPromise { - return $this->promiseAdapter->create(function (callable $resolve) use ($user, $args) { - return $resolve((new ConnectionBuilder())->connectionFromArray($user['friends'], $args)); - }); + return $this->promiseAdapter->create(fn (callable $resolve) => $resolve((new ConnectionBuilder())->connectionFromArray($user['friends'], $args))); } public function resolveNode(Edge $edge): GraphQLPromise { - return $this->promiseAdapter->create(function (callable $resolve) use ($edge) { - return $resolve(isset($this->allUsers[$edge->getNode()]) ? $this->allUsers[$edge->getNode()] : null); - }); + return $this->promiseAdapter->create(fn (callable $resolve) => $resolve(isset($this->allUsers[$edge->getNode()]) ? $this->allUsers[$edge->getNode()] : null)); } public function resolveConnection(): GraphQLPromise { - return $this->promiseAdapter->create(function (callable $resolve) { - return $resolve(count($this->allUsers) - 1); - }); + return $this->promiseAdapter->create(fn (callable $resolve) => $resolve(count($this->allUsers) - 1)); } /** @@ -74,13 +68,9 @@ public function resolveConnection(): GraphQLPromise public function resolveQuery() { if ($this->promiseAdapter instanceof SyncPromiseAdapter) { - return new Deferred(function () { - return $this->allUsers[0]; - }); + return new Deferred(fn () => $this->allUsers[0]); } elseif ($this->promiseAdapter instanceof ReactPromiseAdapter) { - return new ReactPromise(function (callable $resolve) { - return $resolve($this->allUsers[0]); - }); + return new ReactPromise(fn (callable $resolve) => $resolve($this->allUsers[0])); } return $this->allUsers[0]; diff --git a/tests/Functional/App/Resolver/GlobalResolver.php b/tests/Functional/App/Resolver/GlobalResolver.php index c2879237e..cb4f4f468 100644 --- a/tests/Functional/App/Resolver/GlobalResolver.php +++ b/tests/Functional/App/Resolver/GlobalResolver.php @@ -55,7 +55,7 @@ public function __construct(TypeResolver $typeResolver) public function idFetcher(string $globalId): array { - list($type, $id) = array_values(GlobalId::fromGlobalId($globalId)); + [$type, $id] = array_values(GlobalId::fromGlobalId($globalId)); if ('User' === $type) { return $this->userData[$id]; diff --git a/tests/Functional/App/Resolver/SchemaLanguageQueryResolverMap.php b/tests/Functional/App/Resolver/SchemaLanguageQueryResolverMap.php index 48cb2def7..3b55136bc 100644 --- a/tests/Functional/App/Resolver/SchemaLanguageQueryResolverMap.php +++ b/tests/Functional/App/Resolver/SchemaLanguageQueryResolverMap.php @@ -22,17 +22,13 @@ protected function map(): array 'findHumansByDateOfBirth' => function ($value, Argument $args) { $years = $args['years']; - return array_filter(Characters::getHumans(), function ($human) use ($years) { - return in_array($human['dateOfBirth'], $years); - }); + return array_filter(Characters::getHumans(), fn ($human) => in_array($human['dateOfBirth'], $years)); }, 'humans' => [Characters::class, 'getHumans'], 'direwolves' => [Characters::class, 'getDirewolves'], ], 'Character' => [ - self::RESOLVE_TYPE => function ($value) { - return Characters::TYPE_HUMAN === $value['type'] ? 'Human' : 'Direwolf'; - }, + self::RESOLVE_TYPE => fn ($value) => Characters::TYPE_HUMAN === $value['type'] ? 'Human' : 'Direwolf', ], 'Human' => [ 'direwolf' => function ($value) { @@ -51,9 +47,7 @@ protected function map(): array ], // custom scalar 'Year' => [ - self::SCALAR_TYPE => function () { - return new YearScalarType(); - }, + self::SCALAR_TYPE => fn () => new YearScalarType(), ], ]; } diff --git a/tests/Functional/App/config/defaultValue/config.yml b/tests/Functional/App/config/defaultValue/config.yml new file mode 100644 index 000000000..4199fb81e --- /dev/null +++ b/tests/Functional/App/config/defaultValue/config.yml @@ -0,0 +1,14 @@ +imports: + - { resource: ../config.yml } + +overblog_graphql: + definitions: + config_validation: false + class_namespace: "Overblog\\GraphQLBundle\\DefaultValue\\__DEFINITIONS__" + schema: + query: Mutation + mutation: Mutation + mappings: + types: + - type: yaml + dir: "%kernel.project_dir%/config/defaultValue/mapping" diff --git a/tests/Functional/App/config/defaultValue/mapping/Mutation.types.yml b/tests/Functional/App/config/defaultValue/mapping/Mutation.types.yml new file mode 100644 index 000000000..d70148caf --- /dev/null +++ b/tests/Functional/App/config/defaultValue/mapping/Mutation.types.yml @@ -0,0 +1,54 @@ +Mutation: + type: object + config: + fields: + echo: + type: String! + resolve: "@=args['output']" + args: + output: + type: String + defaultValue: 'foo' + isStringNull: + type: Boolean! + resolve: "@=null === args.getArrayCopy()['string']" + args: + string: + type: String + defaultValue: null + echoUsingInput: + type: String! + resolve: "@=args['input']['output']" + args: + input: + type: EchoInput! + isStringNullUsingInput: + type: Boolean! + resolve: "@=null === args.getArrayCopy()['input']['string']" + args: + input: + type: isStringNullInput! + + echoUsingInputWithDefaultArg: + type: String! + resolve: "@=args['input']['output']" + args: + input: + type: EchoInput + defaultValue: {"output": "bar"} + +EchoInput: + type: input-object + config: + fields: + output: + type: String + defaultValue: 'foo' + +isStringNullInput: + type: input-object + config: + fields: + string: + type: String + defaultValue: null diff --git a/tests/Functional/Command/GraphDumpSchemaCommandTest.php b/tests/Functional/Command/GraphDumpSchemaCommandTest.php index b2e39b870..f451b5cb8 100644 --- a/tests/Functional/Command/GraphDumpSchemaCommandTest.php +++ b/tests/Functional/Command/GraphDumpSchemaCommandTest.php @@ -148,8 +148,6 @@ private function sortSchemaEntry(array &$entries, string $entryKey, string $sort $data = &$entries['__schema'][$entryKey]; } - usort($data, function ($data1, $data2) use ($sortBy) { - return strcmp($data1[$sortBy], $data2[$sortBy]); - }); + usort($data, fn ($data1, $data2) => strcmp($data1[$sortBy], $data2[$sortBy])); } } diff --git a/tests/Functional/DefaultValue/DefaultValueTest.php b/tests/Functional/DefaultValue/DefaultValueTest.php new file mode 100644 index 000000000..754037fe5 --- /dev/null +++ b/tests/Functional/DefaultValue/DefaultValueTest.php @@ -0,0 +1,65 @@ + 'defaultValue']); + } + + public function testArgDefaultValue(): void + { + $query = 'mutation { echo }'; + + $result = $this->executeGraphQLRequest($query); + + $this->assertTrue(empty($result['errors'])); + $this->assertSame('foo', $result['data']['echo']); + } + + public function testNullableDefaultValue(): void + { + $query = 'mutation { isStringNull }'; + + $result = $this->executeGraphQLRequest($query); + + $this->assertTrue(empty($result['errors'])); + $this->assertTrue($result['data']['isStringNull']); + } + + public function testArgDefaultValueWithInput(): void + { + $query = 'mutation { echoUsingInput(input: {}) }'; + + $result = $this->executeGraphQLRequest($query); + + $this->assertTrue(empty($result['errors'])); + $this->assertSame('foo', $result['data']['echoUsingInput']); + } + + public function testNullableDefaultValueWithInput(): void + { + $query = 'mutation { isStringNullUsingInput(input: {}) }'; + + $result = $this->executeGraphQLRequest($query); + + $this->assertTrue(empty($result['errors'])); + $this->assertTrue($result['data']['isStringNullUsingInput']); + } + + public function testArgDefaultValueArgWithInput(): void + { + $query = 'mutation { echoUsingInputWithDefaultArg }'; + + $result = $this->executeGraphQLRequest($query); + + $this->assertTrue(empty($result['errors'])); + $this->assertSame('bar', $result['data']['echoUsingInputWithDefaultArg']); + } +} diff --git a/tests/Functional/DisableBuiltInMapping/DisableBuiltInMappingTest.php b/tests/Functional/DisableBuiltInMapping/DisableBuiltInMappingTest.php index 79f3fb2eb..851062261 100644 --- a/tests/Functional/DisableBuiltInMapping/DisableBuiltInMappingTest.php +++ b/tests/Functional/DisableBuiltInMapping/DisableBuiltInMappingTest.php @@ -1,5 +1,7 @@ assertSame( - (new ConnectionBuilder())->getOffsetWithDefault(null, 15), - LegacyConnectionBuilder::getOffsetWithDefault(null, 15) - ); - } - - public function testOffsetToCursor(): void - { - $this->assertSame( - (new ConnectionBuilder())->offsetToCursor(15), - LegacyConnectionBuilder::offsetToCursor(15) - ); - } - - public function testCursorToOffset(): void - { - $this->assertSame( - (new ConnectionBuilder())->cursorToOffset('YXJyYXljb25uZWN0aW9uOjE1'), - LegacyConnectionBuilder::cursorToOffset('YXJyYXljb25uZWN0aW9uOjE1') - ); - } - - public static function getBuilder(): string - { - return LegacyConnectionBuilder::class; - } -} diff --git a/tests/Resolver/Toto.php b/tests/Resolver/Toto.php index 0365f4e3e..a722f13c4 100644 --- a/tests/Resolver/Toto.php +++ b/tests/Resolver/Toto.php @@ -32,9 +32,7 @@ public function getPrivatePropertyWithGetter2(): string public function getPrivatePropertyWithoutGetterUsingCallBack(): Closure { - return function () { - return $this->privatePropertyWithoutGetter; - }; + return fn () => $this->privatePropertyWithoutGetter; } public function resolve(): array