Completed
Push — master ( 7a0180...875ce0 )
by Alexandr
02:39
created

Issue151Test   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 8
dl 0
loc 77
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testInternalVariableArgument() 0 74 2
1
<?php
2
3
namespace Youshido\Tests\Issues\Issue116Test;
4
5
use Youshido\GraphQL\Execution\Processor;
6
use Youshido\GraphQL\Schema\Schema;
7
use Youshido\GraphQL\Type\ListType\ListType;
8
use Youshido\GraphQL\Type\Object\ObjectType;
9
use Youshido\GraphQL\Type\Scalar\IdType;
10
use Youshido\GraphQL\Type\Scalar\StringType;
11
use Youshido\GraphQL\Type\Union\UnionType;
12
13
class Issue151Test extends \PHPUnit_Framework_TestCase
14
{
15
    public function testInternalVariableArgument()
16
    {
17
        $type1 = new ObjectType([
18
            'name'   => 'Type1',
19
            'fields' => [
20
                'id'   => new IdType(),
21
                'name' => new StringType(),
22
            ],
23
        ]);
24
        $type2 = new ObjectType([
25
            'name'   => 'Type2',
26
            'fields' => [
27
                'id'    => new IdType(),
28
                'title' => new StringType(),
29
            ],
30
        ]);
31
32
        $unionType = new UnionType([
33
            'name'        => 'Union',
34
            'types'       => [$type1, $type2],
35
            'resolveType' => function ($value) use ($type1, $type2) {
36
                if (isset($value['name'])) {
37
                    return $type1;
38
                }
39
40
                return $type2;
41
            },
42
        ]);
43
44
        $schema    = new Schema([
45
            'query' => new ObjectType([
46
                'name'   => 'RootQuery',
47
                'fields' => [
48
                    'list' => [
49
                        'type'    => new ListType($unionType),
50
                        'resolve' => function () {
51
                            return [
52
                                [
53
                                    'id'   => 1,
54
                                    'name' => 'name',
55
                                ],
56
                                [
57
                                    'id'    => 2,
58
                                    'title' => 'title',
59
                                ],
60
                            ];
61
                        },
62
                    ],
63
                ],
64
            ]),
65
        ]);
66
        $processor = new Processor($schema);
67
        $response  = $processor->processPayload('
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
68
{
69
    list {
70
        ...UnitFragment
71
    }
72
}
73
74
fragment UnitFragment on Union {
75
    __typename
76
    
77
    ... on Type1 {
78
        id
79
        name
80
    }
81
    ... on Type2 {
82
        id
83
        title
84
    }
85
}
86
        ')->getResponseData();
87
88
    }
89
}
90