Skip to content

Commit beaba14

Browse files
committed
Fix code style
1 parent a69993b commit beaba14

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

src/Config/Parser/GraphQLParser.php

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,34 @@
1414
use GraphQL\Language\AST\ScalarTypeDefinitionNode;
1515
use GraphQL\Language\AST\UnionTypeDefinitionNode;
1616
use GraphQL\Language\Parser;
17+
use Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode;
18+
use Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\EnumNode;
19+
use Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\InputObjectNode;
20+
use Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\InterfaceNode;
1721
use Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\NodeInterface;
22+
use Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\ObjectNode;
23+
use Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\UnionNode;
1824
use SplFileInfo;
1925
use Symfony\Component\Config\Resource\FileResource;
2026
use Symfony\Component\DependencyInjection\ContainerBuilder;
2127
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
28+
2229
use function array_pop;
23-
use function call_user_func;
2430
use function explode;
2531
use function file_get_contents;
26-
use function get_class;
2732
use function preg_replace;
2833
use function sprintf;
2934
use function trim;
30-
use function ucfirst;
3135

3236
class GraphQLParser implements ParserInterface
3337
{
34-
private const DEFINITION_TYPE_MAPPING = [
35-
NodeKind::OBJECT_TYPE_DEFINITION => 'object',
36-
NodeKind::INTERFACE_TYPE_DEFINITION => 'interface',
37-
NodeKind::ENUM_TYPE_DEFINITION => 'enum',
38-
NodeKind::UNION_TYPE_DEFINITION => 'union',
39-
NodeKind::INPUT_OBJECT_TYPE_DEFINITION => 'inputObject',
40-
NodeKind::SCALAR_TYPE_DEFINITION => 'customScalar',
38+
protected const DEFINITION_TYPE_MAPPING = [
39+
NodeKind::OBJECT_TYPE_DEFINITION => ObjectNode::class,
40+
NodeKind::INTERFACE_TYPE_DEFINITION => InterfaceNode::class,
41+
NodeKind::ENUM_TYPE_DEFINITION => EnumNode::class,
42+
NodeKind::UNION_TYPE_DEFINITION => UnionNode::class,
43+
NodeKind::INPUT_OBJECT_TYPE_DEFINITION => InputObjectNode::class,
44+
NodeKind::SCALAR_TYPE_DEFINITION => CustomScalarNode::class,
4145
];
4246

4347
public static function parse(SplFileInfo $file, ContainerBuilder $container, array $configs = []): array
@@ -67,19 +71,28 @@ public static function parse(SplFileInfo $file, ContainerBuilder $container, arr
6771
return $typesConfig;
6872
}
6973

74+
protected static function createUnsupportedDefinitionNodeException(DefinitionNode $typeDef): InvalidArgumentException
75+
{
76+
$path = explode('\\', \get_class($typeDef));
77+
78+
return new InvalidArgumentException(
79+
sprintf(
80+
'%s definition is not supported right now.',
81+
preg_replace('@DefinitionNode$@', '', array_pop($path))
82+
)
83+
);
84+
}
85+
7086
/**
7187
* @return class-string<NodeInterface>
7288
*/
7389
protected static function getNodeClass(DefinitionNode $typeDef): string
7490
{
75-
if (isset($typeDef->kind) && array_key_exists($typeDef->kind, self::DEFINITION_TYPE_MAPPING)) {
76-
/**
77-
* @var class-string<NodeInterface> $class
78-
*/
79-
return sprintf('\\%s\\GraphQL\\ASTConverter\\%sNode', __NAMESPACE__, ucfirst(self::DEFINITION_TYPE_MAPPING[$typeDef->kind]));
91+
if (isset($typeDef->kind) && \array_key_exists($typeDef->kind, static::DEFINITION_TYPE_MAPPING)) {
92+
return static::DEFINITION_TYPE_MAPPING[$typeDef->kind];
8093
}
8194

82-
self::throwUnsupportedDefinitionNode($typeDef);
95+
throw static::createUnsupportedDefinitionNodeException($typeDef);
8396
}
8497

8598
/**
@@ -89,17 +102,6 @@ protected static function prepareConfig(DefinitionNode $typeDef): array
89102
{
90103
$nodeClass = static::getNodeClass($typeDef);
91104

92-
return call_user_func([$nodeClass, 'toConfig'], $typeDef);
93-
}
94-
95-
private static function throwUnsupportedDefinitionNode(DefinitionNode $typeDef): void
96-
{
97-
$path = explode('\\', get_class($typeDef));
98-
throw new InvalidArgumentException(
99-
sprintf(
100-
'%s definition is not supported right now.',
101-
preg_replace('@DefinitionNode$@', '', array_pop($path))
102-
)
103-
);
105+
return \call_user_func([$nodeClass, 'toConfig'], $typeDef);
104106
}
105107
}

0 commit comments

Comments
 (0)