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
Push — 0.11 ( bc751e...035a35 )
by Jérémiah
17s
created

FieldsNode::astValueNodeToConfig()   B

Complexity

Conditions 9
Paths 8

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 9

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 31
ccs 16
cts 16
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?
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?
Loading history...
47 1
                break;
48
49
            case NodeKind::FLOAT:
50 1
                $config = \floatval($valueNode->value);
51 1
                break;
52
53
            case NodeKind::STRING:
54
            case NodeKind::BOOLEAN:
55
            case NodeKind::ENUM:
56 1
                $config = $valueNode->value;
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?
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