VariableTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 37.97 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 30
loc 79
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetValue() 0 6 1
A testGetNullValueException() 0 5 1
A variableProvider() 0 9 1
A testGetValueReturnsDefaultValueIfNoValueSet() 10 10 1
A testGetValueReturnsSetValueEvenWithDefaultValue() 11 11 1
A testIndicatesDefaultValuePresent() 9 9 1
A testHasNoDefaultValue() 0 8 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
namespace Youshido\Tests\Parser;
4
5
use Youshido\GraphQL\Parser\Ast\ArgumentValue\Variable;
6
use Youshido\GraphQL\Parser\Location;
7
8
class VariableTest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * Test if variable value equals expected value
12
     *
13
     * @dataProvider variableProvider
14
     */
15
    public function testGetValue($actual, $expected)
16
    {
17
        $var = new Variable('foo', 'bar', false, false, true, new Location(1,1));
18
        $var->setValue($actual);
19
        $this->assertEquals($var->getValue(), $expected);
20
    }
21
22
    /**
23
     * @expectedException \LogicException
24
     * @expectedExceptionMessage Value is not set for variable "foo"
25
     */
26
    public function testGetNullValueException()
27
    {
28
        $var = new Variable('foo', 'bar', false, false, true, new Location(1,1));
29
        $var->getValue();
30
    }
31
32 View Code Duplication
    public function testGetValueReturnsDefaultValueIfNoValueSet()
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...
33
    {
34
        $var = new Variable('foo', 'bar', false, false, true, new Location(1,1));
35
        $var->setDefaultValue('default-value');
36
37
        $this->assertEquals(
38
            'default-value',
39
            $var->getValue()
40
        );
41
    }
42
43 View Code Duplication
    public function testGetValueReturnsSetValueEvenWithDefaultValue()
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...
44
    {
45
        $var = new Variable('foo', 'bar', false, false, true, new Location(1,1));
46
        $var->setValue('real-value');
47
        $var->setDefaultValue('default-value');
48
49
        $this->assertEquals(
50
            'real-value',
51
            $var->getValue()
52
        );
53
    }
54
55 View Code Duplication
    public function testIndicatesDefaultValuePresent()
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...
56
    {
57
        $var = new Variable('foo', 'bar', false, false, true, new Location(1,1));
58
        $var->setDefaultValue('default-value');
59
60
        $this->assertTrue(
61
            $var->hasDefaultValue()
62
        );
63
    }
64
65
    public function testHasNoDefaultValue()
66
    {
67
        $var = new Variable('foo', 'bar', false, false, true, new Location(1,1));
68
69
        $this->assertFalse(
70
            $var->hasDefaultValue()
71
        );
72
    }
73
74
    /**
75
     * @return array Array of <mixed: value to set, mixed: expected value>
76
     */
77
    public static function variableProvider()
78
    {
79
        return [
80
            [
81
                0,
82
                0
83
            ]
84
        ];
85
    }
86
}
87