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 (#400)
by Jáchym
22:22
created

FieldsNode::toConfig()   B

Complexity

Conditions 6
Paths 2

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 15
cts 15
cp 1
rs 8.8337
c 0
b 0
f 0
cc 6
nc 2
nop 2
crap 6
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 1
                $config = intval($valueNode->value, 10);
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...
47 1
                break;
48
49
            case NodeKind::FLOAT:
50
                $config = floatval($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
                break;
52
53
            case NodeKind::STRING:
54
            case NodeKind::BOOLEAN:
55
            case NodeKind::ENUM:
56 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...
57 1
                break;
58
59
            case NodeKind::LST:
60 1
                $config = [];
61 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...
62 1
                    $config[] = self::astValueNodeToConfig($node);
63
                }
64 1
                break;
65
66
            case NodeKind::NULL:
67 1
                $config = null;
68 1
                break;
69
        }
70
71 1
        return $config;
72
    }
73
}
74