Skip to content

Commit

Permalink
Update PhpCS rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web committed May 4, 2021
1 parent 5356de0 commit e885b67
Show file tree
Hide file tree
Showing 38 changed files with 70 additions and 147 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
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
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
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
2 changes: 1 addition & 1 deletion src/Relay/Connection/Output/Edge.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function setNode($node): void
/**
* {@inheritdoc}
*/
public function getCursor(): ? string
public function getCursor(): ?string
{
return $this->cursor;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Relay/Connection/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Relay/Node/GlobalId.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/Resolver/AccessResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Security/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Transformer/ArgumentsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions tests/Config/Parser/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
*/
class DeprecatedEnum
{
const P1 = 1;
const P2 = 2;
public const P1 = 1;
public const P2 = 2;
}
28 changes: 7 additions & 21 deletions tests/Definition/Type/CustomScalarTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
];
}
Expand All @@ -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));
Expand Down
Loading

0 comments on commit e885b67

Please sign in to comment.