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 — 0.11 ( 393b72...07e5a8 )
by Jérémiah
53s
created

FieldsNode::astValueNodeToConfig()   B

Complexity

Conditions 9
Paths 8

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 9

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 12
cts 12
cp 1
rs 8.0555
c 0
b 0
f 0
cc 9
nc 8
nop 1
crap 9
1
<?php
2
3
namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;
4
5
use GraphQL\Language\AST\Node;
6
use GraphQL\Language\AST\NodeKind;
7
use GraphQL\Language\AST\ValueNode;
8
9
class FieldsNode implements NodeInterface
10
{
11 2
    public static function toConfig(Node $node, $property = 'fields')
12
    {
13 2
        $config = [];
14 2
        if (!empty($node->$property)) {
15 2
            foreach ($node->$property as $definition) {
16
                $fieldConfig = [
17 2
                    'type' => TypeNode::toConfig($definition),
18 2
                    'description' => DescriptionNode::toConfig($definition),
19
                ];
20
21 2
                if (!empty($definition->arguments)) {
22 2
                    $fieldConfig['args'] = self::toConfig($definition, 'arguments');
23
                }
24
25 2
                if (!empty($definition->defaultValue)) {
26 1
                    $fieldConfig['defaultValue'] = self::astValueNodeToConfig($definition->defaultValue);
27
                }
28
29 2
                $directiveConfig = DirectiveNode::toConfig($definition);
30 2
                if (isset($directiveConfig['deprecationReason'])) {
31 1
                    $fieldConfig['deprecationReason'] = $directiveConfig['deprecationReason'];
32
                }
33
34 2
                $config[$definition->name->value] = $fieldConfig;
35
            }
36
        }
37
38 2
        return $config;
39
    }
40
41 1
    private static function astValueNodeToConfig(ValueNode $valueNode)
42
    {
43 1
        $config = null;
44 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...
45
            case NodeKind::INT:
46
            case NodeKind::FLOAT:
47
            case NodeKind::STRING:
48
            case NodeKind::BOOLEAN:
49
            case NodeKind::ENUM:
50 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...
51 1
                break;
52
53
            case NodeKind::LST:
54 1
                $config = [];
55 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...
56 1
                    $config[] = self::astValueNodeToConfig($node);
57
                }
58 1
                break;
59
60
            case NodeKind::NULL:
61 1
                $config = null;
62 1
                break;
63
        }
64
65 1
        return $config;
66
    }
67
}
68