ResultSetTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 51.32 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 39
loc 76
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A getTableName() 0 4 1
A simpleSelect() 0 5 1
A addingOrderBy() 7 7 1
A addingWhere() 8 8 1
A addingWhereInArray() 8 8 1
A addingFullSyntax() 8 8 1
A addingWhereWithoutValue() 8 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 Reduce\Test\Db;
4
5
use Reduce\Db\ResultSet;
6
use Reduce\Db\Connection;
7
use Reduce\Db\Query\QueryBuilder;
8
use Doctrine\DBAL\Driver\PDOSqlite\Driver;
9
10
class ResultSetTest extends \PHPUnit_Framework_TestCase
11
{
12
    const TABLE_NAME = 'tableName';
13
    protected $resultSet;
14
        
15
    protected function setUp()
16
    {
17
        $connection = $this->getMockBuilder('Reduce\Db\Connection')
18
                           ->setConstructorArgs(['global' => ['memory' => true], new Driver])
19
                           ->getMock();
20
        
21
        $this->resultSet = new ResultSet(static::TABLE_NAME, new QueryBuilder($connection));
22
    }
23
        
24
    /** @test */
25
    public function getTableName()
26
    {
27
        $this->assertEquals('tableName', $this->resultSet->getTableName());
28
    }
29
    
30
    /** @test */
31
    public function simpleSelect()
32
    {
33
        $sql = 'SELECT * FROM ' . static::TABLE_NAME;
34
        $this->assertEquals((string) $this->resultSet, $sql);
35
    }
36
    
37
    /** @test */
38 View Code Duplication
    public function addingOrderBy()
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...
39
    {
40
        $this->resultSet->orderBy('id');
0 ignored issues
show
Documentation Bug introduced by
The method orderBy does not exist on object<Reduce\Db\ResultSet>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
41
        $sql = 'SELECT * FROM ' . static::TABLE_NAME . ' ORDER BY id ASC';
42
        
43
        $this->assertEquals((string) $this->resultSet, $sql);
44
    }
45
    
46
    /** @test */
47 View Code Duplication
    public function addingWhere()
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...
48
    {
49
        $this->resultSet->where('id', 1);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Reduce\Db\ResultSet>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
50
        
51
        $sql = 'SELECT * FROM ' . static::TABLE_NAME . ' WHERE id = ?';
52
        
53
        $this->assertEquals((string) $this->resultSet, $sql);
54
    }
55
    
56
    /** @test */
57 View Code Duplication
    public function addingWhereInArray()
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...
58
    {
59
        $this->resultSet->where(['id' => 1]);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Reduce\Db\ResultSet>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
60
        
61
        $sql = 'SELECT * FROM ' . static::TABLE_NAME . ' WHERE id = ?';
62
        
63
        $this->assertEquals((string) $this->resultSet, $sql);
64
    }
65
    
66
    /** @test */
67 View Code Duplication
    public function addingFullSyntax()
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...
68
    {
69
        $this->resultSet->where('id = ?', 1);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Reduce\Db\ResultSet>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
70
        
71
        $sql = 'SELECT * FROM ' . static::TABLE_NAME . ' WHERE id = ?';
72
        
73
        $this->assertEquals((string) $this->resultSet, $sql);
74
    }
75
76
    /** @test */
77 View Code Duplication
    public function addingWhereWithoutValue()
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...
78
    {
79
        $this->resultSet->where('id IS NULL');
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Reduce\Db\ResultSet>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
80
        
81
        $sql = 'SELECT * FROM ' . static::TABLE_NAME . ' WHERE id IS NULL';
82
        
83
        $this->assertEquals((string) $this->resultSet, $sql);
84
    }
85
}