ConnectionTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 6
dl 14
loc 42
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testConnectionArgs() 0 10 1
A testPageInfoType() 0 10 1
A testEdgeDefinition() 7 7 1
A testConnectionDefinition() 7 7 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
 * This file is a part of GraphQL project.
4
 *
5
 * @author Alexandr Viniychuk <[email protected]>
6
 * created: 10:39 PM 5/18/16
7
 */
8
9
namespace Youshido\Tests\Library\Relay;
10
11
12
use Youshido\GraphQL\Relay\Connection\Connection;
13
use Youshido\GraphQL\Relay\Type\PageInfoType;
14
use Youshido\GraphQL\Type\Scalar\StringType;
15
use Youshido\GraphQL\Type\TypeMap;
16
use Youshido\Tests\DataProvider\TestObjectType;
17
18
class ConnectionTest extends \PHPUnit_Framework_TestCase
19
{
20
21
    public function testConnectionArgs()
22
    {
23
        $this->assertEquals([
24
            'after'  => ['type' => TypeMap::TYPE_STRING],
25
            'first'  => ['type' => TypeMap::TYPE_INT],
26
            'before' => ['type' => TypeMap::TYPE_STRING],
27
            'last'   => ['type' => TypeMap::TYPE_INT],
28
29
        ], Connection::connectionArgs());
30
    }
31
32
    public function testPageInfoType()
33
    {
34
        $type = new PageInfoType();
35
        $this->assertEquals('PageInfo', $type->getName());
36
        $this->assertEquals('Information about pagination in a connection.', $type->getDescription());
37
        $this->assertTrue($type->hasField('hasNextPage'));
38
        $this->assertTrue($type->hasField('hasPreviousPage'));
39
        $this->assertTrue($type->hasField('startCursor'));
40
        $this->assertTrue($type->hasField('endCursor'));
41
    }
42
43 View Code Duplication
    public function testEdgeDefinition()
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
        $edgeType = Connection::edgeDefinition(new StringType(), 'user');
46
        $this->assertEquals('userEdge', $edgeType->getName());
47
        $this->assertTrue($edgeType->hasField('node'));
48
        $this->assertTrue($edgeType->hasField('cursor'));
49
    }
50
51 View Code Duplication
    public function testConnectionDefinition()
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...
52
    {
53
        $connection = Connection::connectionDefinition(new TestObjectType(), 'user');
54
        $this->assertEquals($connection->getName(), 'userConnection');
55
        $this->assertTrue($connection->hasField('pageInfo'));
56
        $this->assertTrue($connection->hasField('edges'));
57
    }
58
59
}
60