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

Completed
Pull Request — 0.11 (#375)
by Jérémiah
27:12 queued 07:34
created

GraphQLParser::addDefaultValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
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\NodeList;
12
use GraphQL\Language\AST\TypeNode;
13
use GraphQL\Language\AST\ValueNode;
14
use GraphQL\Language\Parser;
15
use GraphQL\Type\Definition\Directive;
16
use Symfony\Component\Config\Resource\FileResource;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
19
20
class GraphQLParser implements ParserInterface
21
{
22
    /** @var self */
23
    private static $parser;
24
25
    const DEFINITION_TYPE_MAPPING = [
26
        NodeKind::OBJECT_TYPE_DEFINITION => 'object',
27
        NodeKind::INTERFACE_TYPE_DEFINITION => 'interface',
28
        NodeKind::ENUM_TYPE_DEFINITION => 'enum',
29
        NodeKind::UNION_TYPE_DEFINITION => 'union',
30
        NodeKind::INPUT_OBJECT_TYPE_DEFINITION => 'input-object',
31
        NodeKind::SCALAR_TYPE_DEFINITION => 'custom-scalar',
32
    ];
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 5
    public static function parse(\SplFileInfo $file, ContainerBuilder $container)
38
    {
39 5
        $container->addResource(new FileResource($file->getRealPath()));
40 5
        $content = \trim(\file_get_contents($file->getPathname()));
41 5
        $typesConfig = [];
42
43
        // allow empty files
44 5
        if (empty($content)) {
45 1
            return [];
46
        }
47 4
        if (!self::$parser) {
48 1
            self::$parser = new static();
49
        }
50
        try {
51 4
            $ast = Parser::parse($content);
52 1
        } catch (\Exception $e) {
53 1
            throw new InvalidArgumentException(\sprintf('An error occurred while parsing the file "%s".', $file), $e->getCode(), $e);
54
        }
55
56 3
        foreach ($ast->definitions as $typeDef) {
57 3
            if (isset($typeDef->name) && $typeDef->name instanceof NameNode) {
58 2
                $typeConfig = self::$parser->typeDefinitionToConfig($typeDef);
59 2
                $typesConfig[$typeDef->name->value] = $typeConfig;
60
            } else {
61 3
                self::throwUnsupportedDefinitionNode($typeDef);
62
            }
63
        }
64
65 2
        return $typesConfig;
66
    }
67
68 1
    public static function mustOverrideConfig()
69
    {
70 1
        throw new \RuntimeException('Config entry must be override with ResolverMap to be used.');
71
    }
72
73 2
    protected function typeDefinitionToConfig(DefinitionNode $typeDef)
74
    {
75 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...
76 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...
77 2
                case NodeKind::OBJECT_TYPE_DEFINITION:
78 2
                case NodeKind::INTERFACE_TYPE_DEFINITION:
79 2
                case NodeKind::INPUT_OBJECT_TYPE_DEFINITION:
80 2
                case NodeKind::ENUM_TYPE_DEFINITION:
81 2
                case NodeKind::UNION_TYPE_DEFINITION:
82 2
                    $config = [];
83 2
                    $this->addTypeFields($typeDef, $config);
84 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...
85 2
                    $this->addInterfaces($typeDef, $config);
86 2
                    $this->addTypes($typeDef, $config);
87 2
                    $this->addValues($typeDef, $config);
88
89
                    return [
90 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...
91 2
                        'config' => $config,
92
                    ];
93
94 2
                case NodeKind::SCALAR_TYPE_DEFINITION:
95 2
                    $mustOverride = [__CLASS__, 'mustOverrideConfig'];
96
                    $config = [
97 2
                        'serialize' => $mustOverride,
98 2
                        'parseValue' => $mustOverride,
99 2
                        'parseLiteral' => $mustOverride,
100
                    ];
101 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...
102
103
                    return [
104 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...
105 2
                        'config' => $config,
106
                    ];
107
                    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...
108
109
                default:
110
                    self::throwUnsupportedDefinitionNode($typeDef);
111
            }
112
        }
113
114
        self::throwUnsupportedDefinitionNode($typeDef);
115
    }
116
117 1
    private static function throwUnsupportedDefinitionNode(DefinitionNode $typeDef)
118
    {
119 1
        $path = \explode('\\', \get_class($typeDef));
120 1
        throw new InvalidArgumentException(
121 1
            \sprintf(
122 1
                '%s definition is not supported right now.',
123 1
                \preg_replace('@DefinitionNode$@', '', \array_pop($path))
124
            )
125
        );
126
    }
127
128
    /**
129
     * @param DefinitionNode $typeDef
130
     * @param array          $config
131
     */
132 2
    private function addTypeFields(DefinitionNode $typeDef, array &$config)
133
    {
134 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...
135 2
            $fields = [];
136
            /** @var FieldDefinitionNode|InputValueDefinitionNode $fieldDef */
137 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...
138 2
                $fieldName = $fieldDef->name->value;
139 2
                $fields[$fieldName] = [];
140 2
                $this->addType($fieldDef, $fields[$fieldName]);
141 2
                $this->addDescription($fieldDef, $fields[$fieldName]);
142 2
                $this->addDefaultValue($fieldDef, $fields[$fieldName]);
143 2
                $this->addFieldArguments($fieldDef, $fields[$fieldName]);
144 2
                $this->addFromDirectives($fieldDef->directives, $fields[$fieldName]);
145
            }
146 2
            $config['fields'] = $fields;
147
        }
148 2
    }
149
150
    /**
151
     * @param Node  $fieldDef
152
     * @param array $fieldConf
153
     */
154 2
    private function addFieldArguments(Node $fieldDef, array &$fieldConf)
155
    {
156 2
        if (!empty($fieldDef->arguments)) {
157 2
            $arguments = [];
158 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...
159 2
                $name = $definition->name->value;
160 2
                $arguments[$name] = [];
161 2
                $this->addType($definition, $arguments[$name]);
162 2
                $this->addDescription($definition, $arguments[$name]);
163 2
                $this->addDefaultValue($definition, $arguments[$name]);
164
            }
165 2
            $fieldConf['args'] = $arguments;
166
        }
167 2
    }
168
169
    /**
170
     * @param DefinitionNode $typeDef
171
     * @param array          $config
172
     */
173 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...
174
    {
175 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...
176 2
            $interfaces = [];
177 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...
178 2
                $interfaces[] = $this->astTypeNodeToString($interface);
179
            }
180 2
            $config['interfaces'] = $interfaces;
181
        }
182 2
    }
183
184
    /**
185
     * @param DefinitionNode $typeDef
186
     * @param array          $config
187
     */
188 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...
189
    {
190 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...
191 1
            $types = [];
192 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...
193 1
                $types[] = $this->astTypeNodeToString($type);
194
            }
195 1
            $config['types'] = $types;
196
        }
197 2
    }
198
199
    /**
200
     * @param DefinitionNode $typeDef
201
     * @param array          $config
202
     */
203 2
    private function addValues(DefinitionNode $typeDef, array &$config)
204
    {
205 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...
206 2
            $values = [];
207 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...
208 2
                $values[$value->name->value] = ['value' => $value->name->value];
209 2
                $this->addDescription($value, $values[$value->name->value]);
210 2
                $this->addFromDirectives($value->directives, $values[$value->name->value]);
211
            }
212 2
            $config['values'] = $values;
213
        }
214 2
    }
215
216 2
    private function addFromDirectives(NodeList $directives, array &$config)
217
    {
218 2
        if ($directives->count()) {
219 1
            foreach ($directives as $directiveDef) {
220 1
                if ('deprecated' === $directiveDef->name->value) {
221 1
                    $reason = $directiveDef->arguments->count() ?
222 1
                        $directiveDef->arguments[0]->value->value : Directive::DEFAULT_DEPRECATION_REASON;
223
224 1
                    $config['deprecationReason'] = $reason;
225
                }
226
            }
227
        }
228 2
    }
229
230
    /**
231
     * @param Node  $definition
232
     * @param array $config
233
     */
234 2
    private function addType(Node $definition, array &$config)
235
    {
236 2
        if (!empty($definition->type)) {
237 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...
238
        }
239 2
    }
240
241
    /**
242
     * @param Node  $definition
243
     * @param array $config
244
     */
245 2
    private function addDescription(Node $definition, array &$config)
246
    {
247
        if (
248 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...
249 2
            && $description = $this->cleanAstDescription($definition->description)
250
        ) {
251 1
            $config['description'] = $description;
252
        }
253 2
    }
254
255
    /**
256
     * @param Node  $definition
257
     * @param array $config
258
     */
259 2
    private function addDefaultValue(Node $definition, array &$config)
260
    {
261 2
        if (!empty($definition->defaultValue)) {
262 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...
263
        }
264 2
    }
265
266 2
    private function astTypeNodeToString(TypeNode $typeNode)
267
    {
268 2
        $type = '';
269 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...
270 2
            case NodeKind::NAMED_TYPE:
271 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...
272 2
                break;
273
274 2
            case NodeKind::NON_NULL_TYPE:
275 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...
276 2
                break;
277
278 2
            case NodeKind::LIST_TYPE:
279 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...
280 2
                break;
281
        }
282
283 2
        return $type;
284
    }
285
286 1
    private function astValueNodeToConfig(ValueNode $valueNode)
287
    {
288 1
        $config = null;
289 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...
290 1
            case NodeKind::INT:
291 1
            case NodeKind::FLOAT:
292 1
            case NodeKind::STRING:
293 1
            case NodeKind::BOOLEAN:
294 1
            case NodeKind::ENUM:
295 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...
296 1
                break;
297
298 1
            case NodeKind::LST:
299 1
                $config = [];
300 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...
301 1
                    $config[] = $this->astValueNodeToConfig($node);
302
                }
303 1
                break;
304
305 1
            case NodeKind::NULL:
306 1
                $config = null;
307 1
                break;
308
        }
309
310 1
        return $config;
311
    }
312
313 1
    private function cleanAstDescription($description)
314
    {
315 1
        if (\property_exists($description, 'value')) {
316 1
            $description = $description->value;
317
        }
318 1
        $description = \trim($description);
319
320 1
        return empty($description) ? null : $description;
321
    }
322
}
323