Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — 0.11 (#435)
by Jérémiah
13:02
created

GraphQLParser   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 29
dl 0
loc 49
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 26 6
A throwUnsupportedDefinitionNode() 0 7 1
1
<?php
2
3
namespace Overblog\GraphQLBundle\Config\Parser;
4
5
use GraphQL\Language\AST\DefinitionNode;
6
use GraphQL\Language\AST\NodeKind;
7
use GraphQL\Language\Parser;
8
use Symfony\Component\Config\Resource\FileResource;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
11
12
class GraphQLParser implements ParserInterface
13
{
14
    const DEFINITION_TYPE_MAPPING = [
15
        NodeKind::OBJECT_TYPE_DEFINITION => 'object',
16
        NodeKind::INTERFACE_TYPE_DEFINITION => 'interface',
17
        NodeKind::ENUM_TYPE_DEFINITION => 'enum',
18
        NodeKind::UNION_TYPE_DEFINITION => 'union',
19
        NodeKind::INPUT_OBJECT_TYPE_DEFINITION => 'inputObject',
20
        NodeKind::SCALAR_TYPE_DEFINITION => 'customScalar',
21
    ];
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 5
    public static function parse(\SplFileInfo $file, ContainerBuilder $container)
27
    {
28 5
        $container->addResource(new FileResource($file->getRealPath()));
29 5
        $content = \trim(\file_get_contents($file->getPathname()));
30 5
        $typesConfig = [];
31
32
        // allow empty files
33 5
        if (empty($content)) {
34 1
            return [];
35
        }
36
        try {
37 4
            $ast = Parser::parse($content);
38 1
        } catch (\Exception $e) {
39 1
            throw new InvalidArgumentException(\sprintf('An error occurred while parsing the file "%s".', $file), $e->getCode(), $e);
40
        }
41
42 3
        foreach ($ast->definitions as $typeDef) {
43 3
            if (isset($typeDef->kind) && \in_array($typeDef->kind, \array_keys(self::DEFINITION_TYPE_MAPPING))) {
0 ignored issues
show
Bug introduced by
Accessing kind on the interface GraphQL\Language\AST\DefinitionNode suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
44 2
                $class = \sprintf('\\%s\\GraphQL\\ASTConverter\\%sNode', __NAMESPACE__, \ucfirst(self::DEFINITION_TYPE_MAPPING[$typeDef->kind]));
45 2
                $typesConfig[$typeDef->name->value] = \call_user_func([$class, 'toConfig'], $typeDef);
0 ignored issues
show
Bug introduced by
Accessing name on the interface GraphQL\Language\AST\DefinitionNode suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
46
            } else {
47 3
                self::throwUnsupportedDefinitionNode($typeDef);
48
            }
49
        }
50
51 2
        return $typesConfig;
52
    }
53
54 1
    private static function throwUnsupportedDefinitionNode(DefinitionNode $typeDef)
55
    {
56 1
        $path = \explode('\\', \get_class($typeDef));
57 1
        throw new InvalidArgumentException(
58 1
            \sprintf(
59 1
                '%s definition is not supported right now.',
60 1
                \preg_replace('@DefinitionNode$@', '', \array_pop($path))
61
            )
62
        );
63
    }
64
}
65