Skip to content

Commit

Permalink
Merge branch '0.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web committed May 4, 2021
2 parents bee2e36 + 5b10c26 commit 40b7eac
Show file tree
Hide file tree
Showing 48 changed files with 224 additions and 339 deletions.
6 changes: 5 additions & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
=======================
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions src/Config/ObjectTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Parser/AnnotationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class AnnotationParser extends MetadataParser
{
const METADATA_FORMAT = '@%s';
public const METADATA_FORMAT = '@%s';

protected static ?AnnotationReader $annotationReader = null;

Expand Down
2 changes: 1 addition & 1 deletion src/Config/Parser/AttributeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class AttributeParser extends MetadataParser
{
const METADATA_FORMAT = '#[%s]';
public const METADATA_FORMAT = '#[%s]';

public static function getMetadatas(Reflector $reflector): array
{
Expand Down
16 changes: 7 additions & 9 deletions src/Config/Parser/MetadataParser/MetadataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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()));
Expand All @@ -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 {
Expand Down Expand Up @@ -929,7 +927,7 @@ private static function guessType(ReflectionClass $reflectionClass, Reflector $r
}
}

throw new TypeGuessingException(join("\n", $errors));
throw new TypeGuessingException(implode("\n", $errors));
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Config/Processor/InheritanceProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions src/Definition/Argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Type/CustomScalarType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/DependencyInjection/Compiler/ConfigParserPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 1 addition & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/TypesConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getConfigTreeBuilder()
}
}

return false;
return false;
})
->thenInvalid(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})";
}
Expand Down
14 changes: 10 additions & 4 deletions src/Generator/TypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
10 changes: 3 additions & 7 deletions src/Relay/Connection/ConnectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -189,17 +187,15 @@ 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));
}

/**
* Return the cursor associated with an object in an array.
*
* @param mixed $object
*/
public function cursorForObjectInConnection(array $data, $object): ? string
public function cursorForObjectInConnection(array $data, $object): ?string
{
$offset = null;

Expand Down
2 changes: 1 addition & 1 deletion src/Relay/Connection/EdgeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function setNode($node): void;
*
* @return string
*/
public function getCursor(): ? string;
public function getCursor(): ?string;

/**
* Set the edge cursor.
Expand Down
2 changes: 1 addition & 1 deletion src/Relay/Connection/Output/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function setEdges(iterable $edges): void
/**
* {@inheritdoc}
*/
public function getPageInfo(): ? PageInfoInterface
public function getPageInfo(): ?PageInfoInterface
{
return $this->pageInfo;
}
Expand Down
Loading

0 comments on commit 40b7eac

Please sign in to comment.