Completed
Push — master ( 17976d...325209 )
by Portey
07:00
created

UnionResolveTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 18.64 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 2
c 1
b 1
f 1
lcom 0
cbo 4
dl 11
loc 59
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testResolve() 11 11 1
B dataProvider() 0 36 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Date: 16.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\Tests\Type\Union;
9
10
11
use Youshido\GraphQL\Processor;
12
use Youshido\GraphQL\Validator\ResolveValidator\ResolveValidator;
13
use Youshido\Tests\Type\Union\Schema\Schema;
14
15
class UnionResolveTest extends \PHPUnit_Framework_TestCase
16
{
17
18
    /**
19
     * @param $query
20
     * @param $response
21
     *
22
     * @dataProvider dataProvider
23
     */
24 View Code Duplication
    public function testResolve($query, $response)
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...
25
    {
26
        $processor = new Processor(new ResolveValidator());
27
        $processor->setSchema(new Schema());
28
29
        $processor->processQuery($query);
30
31
        $a = $processor->getResponseData();
0 ignored issues
show
Unused Code introduced by
$a 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...
32
33
        $this->assertEquals($processor->getResponseData(), $response);
34
    }
35
36
    public function dataProvider()
37
    {
38
        return [
39
            [
40
                '{
41
                    oneUnion {
42
                        name
43
                    }
44
                }',
45
                [
46
                    'data' => [
47
                        'oneUnion' => [
48
                            'name' => 'object one'
49
                        ]
50
                    ]
51
                ]
52
            ],
53
            [
54
                '{
55
                    list : unionList {
56
                        name
57
                    }
58
                }',
59
                [
60
                    'data' => [
61
                        'list' => [
62
                            ['name' => 'object 1'],
63
                            ['name' => 'object 2'],
64
                            ['name' => 'object 3'],
65
                            ['name' => 'object 4']
66
                        ]
67
                    ]
68
                ]
69
            ]
70
        ];
71
    }
72
73
}