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
Push — master ( 921329...8d19ff )
by Jérémiah
17:19
created

GraphQLParser   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 287
Duplicated Lines 6.97 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 97.96%

Importance

Changes 0
Metric Value
wmc 55
lcom 1
cbo 5
dl 20
loc 287
ccs 144
cts 147
cp 0.9796
rs 6.8
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
C parse() 0 30 7
A mustOverrideConfig() 0 4 1
C typeDefinitionToConfig() 0 43 8
A throwUnsupportedDefinitionNode() 0 10 1
A addTypeFields() 0 16 3
A addFieldArguments() 0 14 3
A addInterfaces() 10 10 3
A addTypes() 10 10 3
A addValues() 0 11 3
A addType() 0 6 2
A addDescription() 0 9 3
A addDefaultValue() 0 6 2
A astTypeNodeToString() 0 19 4
D astValueNodeToConfig() 0 26 9
A cleanAstDescription() 0 9 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like GraphQLParser often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use GraphQLParser, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Overblog\GraphQLBundle\Config\Parser;
4
5
use GraphQL\Language\AST\DefinitionNode;
6
use GraphQL\Language\AST\FieldDefinitionNode;
7
use GraphQL\Language\AST\InputValueDefinitionNode;
8
use GraphQL\Language\AST\NameNode;
9
use GraphQL\Language\AST\Node;
10
use GraphQL\Language\AST\NodeKind;
11
use GraphQL\Language\AST\TypeNode;
12
use GraphQL\Language\AST\ValueNode;
13
use GraphQL\Language\Parser;
14
use Symfony\Component\Config\Resource\FileResource;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
17
18
class GraphQLParser implements ParserInterface
19
{
20
    /** @var self */
21
    private static $parser;
22
23
    const DEFINITION_TYPE_MAPPING = [
24
        NodeKind::OBJECT_TYPE_DEFINITION => 'object',
25
        NodeKind::INTERFACE_TYPE_DEFINITION => 'interface',
26
        NodeKind::ENUM_TYPE_DEFINITION => 'enum',
27
        NodeKind::UNION_TYPE_DEFINITION => 'union',
28
        NodeKind::INPUT_OBJECT_TYPE_DEFINITION => 'input-object',
29
        NodeKind::SCALAR_TYPE_DEFINITION => 'custom-scalar',
30
    ];
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 5
    public static function parse(\SplFileInfo $file, ContainerBuilder $container)
36
    {
37 5
        $container->addResource(new FileResource($file->getRealPath()));
38 5
        $content = trim(file_get_contents($file->getPathname()));
39 5
        $typesConfig = [];
40
41
        // allow empty files
42 5
        if (empty($content)) {
43 1
            return [];
44
        }
45 4
        if (!self::$parser) {
46 1
            self::$parser = new static();
47
        }
48
        try {
49 4
            $ast = Parser::parse($content);
50 1
        } catch (\Exception $e) {
51 1
            throw new InvalidArgumentException(sprintf('An error occurred while parsing the file "%s".', $file), $e->getCode(), $e);
52
        }
53
54 3
        foreach ($ast->definitions as $typeDef) {
55 3
            if (isset($typeDef->name) && $typeDef->name instanceof NameNode) {
56 2
                $typeConfig = self::$parser->typeDefinitionToConfig($typeDef);
57 2
                $typesConfig[$typeDef->name->value] = $typeConfig;
58
            } else {
59 3
                self::throwUnsupportedDefinitionNode($typeDef);
60
            }
61
        }
62
63 2
        return $typesConfig;
64
    }
65
66 1
    public static function mustOverrideConfig()
67
    {
68 1
        throw new \RuntimeException('Config entry must be override with ResolverMap to be used.');
69
    }
70
71 2
    protected function typeDefinitionToConfig(DefinitionNode $typeDef)
72
    {
73 2
        if (isset($typeDef->kind)) {
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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
74 2
            switch ($typeDef->kind) {
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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
75 2
                case NodeKind::OBJECT_TYPE_DEFINITION:
76 2
                case NodeKind::INTERFACE_TYPE_DEFINITION:
77 2
                case NodeKind::INPUT_OBJECT_TYPE_DEFINITION:
78 2
                case NodeKind::ENUM_TYPE_DEFINITION:
79 2
                case NodeKind::UNION_TYPE_DEFINITION:
80 2
                    $config = [];
81 2
                    $this->addTypeFields($typeDef, $config);
82 2
                    $this->addDescription($typeDef, $config);
0 ignored issues
show
Documentation introduced by
$typeDef is of type object<GraphQL\Language\AST\DefinitionNode>, but the function expects a object<GraphQL\Language\AST\Node>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
83 2
                    $this->addInterfaces($typeDef, $config);
84 2
                    $this->addTypes($typeDef, $config);
85 2
                    $this->addValues($typeDef, $config);
86
87
                    return [
88 2
                        'type' => self::DEFINITION_TYPE_MAPPING[$typeDef->kind],
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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
89 2
                        'config' => $config,
90
                    ];
91
92 2
                case NodeKind::SCALAR_TYPE_DEFINITION:
93 2
                    $mustOverride = [__CLASS__, 'mustOverrideConfig'];
94
                    $config = [
95 2
                        'serialize' => $mustOverride,
96 2
                        'parseValue' => $mustOverride,
97 2
                        'parseLiteral' => $mustOverride,
98
                    ];
99 2
                    $this->addDescription($typeDef, $config);
0 ignored issues
show
Documentation introduced by
$typeDef is of type object<GraphQL\Language\AST\DefinitionNode>, but the function expects a object<GraphQL\Language\AST\Node>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
100
101
                    return [
102 2
                        'type' => self::DEFINITION_TYPE_MAPPING[$typeDef->kind],
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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
103 2
                        'config' => $config,
104
                    ];
105
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
106
107
                default:
108
                    self::throwUnsupportedDefinitionNode($typeDef);
109
            }
110
        }
111
112
        self::throwUnsupportedDefinitionNode($typeDef);
113
    }
114
115 1
    private static function throwUnsupportedDefinitionNode(DefinitionNode $typeDef)
116
    {
117 1
        $path = explode('\\', get_class($typeDef));
118 1
        throw new InvalidArgumentException(
119 1
            sprintf(
120 1
                '%s definition is not supported right now.',
121 1
                preg_replace('@DefinitionNode$@', '', array_pop($path))
122
            )
123
        );
124
    }
125
126
    /**
127
     * @param DefinitionNode $typeDef
128
     * @param array          $config
129
     */
130 2
    private function addTypeFields(DefinitionNode $typeDef, array &$config)
131
    {
132 2
        if (!empty($typeDef->fields)) {
0 ignored issues
show
Bug introduced by
Accessing fields on the interface GraphQL\Language\AST\DefinitionNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
133 2
            $fields = [];
134
            /** @var FieldDefinitionNode|InputValueDefinitionNode $fieldDef */
135 2
            foreach ($typeDef->fields as $fieldDef) {
0 ignored issues
show
Bug introduced by
Accessing fields on the interface GraphQL\Language\AST\DefinitionNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
136 2
                $fieldName = $fieldDef->name->value;
137 2
                $fields[$fieldName] = [];
138 2
                $this->addType($fieldDef, $fields[$fieldName]);
139 2
                $this->addDescription($fieldDef, $fields[$fieldName]);
140 2
                $this->addDefaultValue($fieldDef, $fields[$fieldName]);
141 2
                $this->addFieldArguments($fieldDef, $fields[$fieldName]);
142
            }
143 2
            $config['fields'] = $fields;
144
        }
145 2
    }
146
147
    /**
148
     * @param Node  $fieldDef
149
     * @param array $fieldConf
150
     */
151 2
    private function addFieldArguments(Node $fieldDef, array &$fieldConf)
152
    {
153 2
        if (!empty($fieldDef->arguments)) {
154 2
            $arguments = [];
155 2
            foreach ($fieldDef->arguments as $definition) {
0 ignored issues
show
Bug introduced by
The property arguments does not seem to exist in GraphQL\Language\AST\Node.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
156 2
                $name = $definition->name->value;
157 2
                $arguments[$name] = [];
158 2
                $this->addType($definition, $arguments[$name]);
159 2
                $this->addDescription($definition, $arguments[$name]);
160 2
                $this->addDefaultValue($definition, $arguments[$name]);
161
            }
162 2
            $fieldConf['args'] = $arguments;
163
        }
164 2
    }
165
166
    /**
167
     * @param DefinitionNode $typeDef
168
     * @param array          $config
169
     */
170 2 View Code Duplication
    private function addInterfaces(DefinitionNode $typeDef, array &$config)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
171
    {
172 2
        if (!empty($typeDef->interfaces)) {
0 ignored issues
show
Bug introduced by
Accessing interfaces on the interface GraphQL\Language\AST\DefinitionNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
173 2
            $interfaces = [];
174 2
            foreach ($typeDef->interfaces as $interface) {
0 ignored issues
show
Bug introduced by
Accessing interfaces on the interface GraphQL\Language\AST\DefinitionNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
175 2
                $interfaces[] = $this->astTypeNodeToString($interface);
176
            }
177 2
            $config['interfaces'] = $interfaces;
178
        }
179 2
    }
180
181
    /**
182
     * @param DefinitionNode $typeDef
183
     * @param array          $config
184
     */
185 2 View Code Duplication
    private function addTypes(DefinitionNode $typeDef, array &$config)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
186
    {
187 2
        if (!empty($typeDef->types)) {
0 ignored issues
show
Bug introduced by
Accessing types on the interface GraphQL\Language\AST\DefinitionNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
188 1
            $types = [];
189 1
            foreach ($typeDef->types as $type) {
0 ignored issues
show
Bug introduced by
Accessing types on the interface GraphQL\Language\AST\DefinitionNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
190 1
                $types[] = $this->astTypeNodeToString($type);
191
            }
192 1
            $config['types'] = $types;
193
        }
194 2
    }
195
196
    /**
197
     * @param DefinitionNode $typeDef
198
     * @param array          $config
199
     */
200 2
    private function addValues(DefinitionNode $typeDef, array &$config)
201
    {
202 2
        if (!empty($typeDef->values)) {
0 ignored issues
show
Bug introduced by
Accessing values on the interface GraphQL\Language\AST\DefinitionNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
203 2
            $values = [];
204 2
            foreach ($typeDef->values as $value) {
0 ignored issues
show
Bug introduced by
Accessing values on the interface GraphQL\Language\AST\DefinitionNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
205 2
                $values[$value->name->value] = ['value' => $value->name->value];
206 2
                $this->addDescription($value, $values[$value->name->value]);
207
            }
208 2
            $config['values'] = $values;
209
        }
210 2
    }
211
212
    /**
213
     * @param Node  $definition
214
     * @param array $config
215
     */
216 2
    private function addType(Node $definition, array &$config)
217
    {
218 2
        if (!empty($definition->type)) {
219 2
            $config['type'] = $this->astTypeNodeToString($definition->type);
0 ignored issues
show
Bug introduced by
The property type does not seem to exist in GraphQL\Language\AST\Node.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
220
        }
221 2
    }
222
223
    /**
224
     * @param Node  $definition
225
     * @param array $config
226
     */
227 2
    private function addDescription(Node $definition, array &$config)
228
    {
229
        if (
230 2
            !empty($definition->description)
0 ignored issues
show
Bug introduced by
The property description does not seem to exist in GraphQL\Language\AST\Node.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
231 2
            && $description = $this->cleanAstDescription($definition->description)
232
        ) {
233 1
            $config['description'] = $description;
234
        }
235 2
    }
236
237
    /**
238
     * @param Node  $definition
239
     * @param array $config
240
     */
241 2
    private function addDefaultValue(Node $definition, array &$config)
242
    {
243 2
        if (!empty($definition->defaultValue)) {
244 1
            $config['defaultValue'] = $this->astValueNodeToConfig($definition->defaultValue);
0 ignored issues
show
Bug introduced by
The property defaultValue does not seem to exist in GraphQL\Language\AST\Node.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
245
        }
246 2
    }
247
248 2
    private function astTypeNodeToString(TypeNode $typeNode)
249
    {
250 2
        $type = '';
251 2
        switch ($typeNode->kind) {
0 ignored issues
show
Bug introduced by
Accessing kind on the interface GraphQL\Language\AST\TypeNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
252 2
            case NodeKind::NAMED_TYPE:
253 2
                $type = $typeNode->name->value;
0 ignored issues
show
Bug introduced by
Accessing name on the interface GraphQL\Language\AST\TypeNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
254 2
                break;
255
256 2
            case NodeKind::NON_NULL_TYPE:
257 2
                $type = $this->astTypeNodeToString($typeNode->type).'!';
0 ignored issues
show
Bug introduced by
Accessing type on the interface GraphQL\Language\AST\TypeNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
258 2
                break;
259
260 2
            case NodeKind::LIST_TYPE:
261 2
                $type = '['.$this->astTypeNodeToString($typeNode->type).']';
0 ignored issues
show
Bug introduced by
Accessing type on the interface GraphQL\Language\AST\TypeNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
262 2
                break;
263
        }
264
265 2
        return $type;
266
    }
267
268 1
    private function astValueNodeToConfig(ValueNode $valueNode)
269
    {
270 1
        $config = null;
271 1
        switch ($valueNode->kind) {
0 ignored issues
show
Bug introduced by
Accessing kind on the interface GraphQL\Language\AST\ValueNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
272 1
            case NodeKind::INT:
273 1
            case NodeKind::FLOAT:
274 1
            case NodeKind::STRING:
275 1
            case NodeKind::BOOLEAN:
276 1
            case NodeKind::ENUM:
277 1
                $config = $valueNode->value;
0 ignored issues
show
Bug introduced by
Accessing value on the interface GraphQL\Language\AST\ValueNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
278 1
                break;
279
280 1
            case NodeKind::LST:
281 1
                $config = [];
282 1
                foreach ($valueNode->values as $node) {
0 ignored issues
show
Bug introduced by
Accessing values on the interface GraphQL\Language\AST\ValueNode suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
283 1
                    $config[] = $this->astValueNodeToConfig($node);
284
                }
285 1
                break;
286
287 1
            case NodeKind::NULL:
288 1
                $config = null;
289 1
                break;
290
        }
291
292 1
        return $config;
293
    }
294
295 1
    private function cleanAstDescription($description)
296
    {
297 1
        if (property_exists($description, 'value')) {
298 1
            $description = $description->value;
299
        }
300 1
        $description = trim($description);
301
302 1
        return empty($description) ? null : $description;
303
    }
304
}
305