Completed
Push — master ( 67b49c...8d83b9 )
by Joao
26s queued 11s
created

SqliteDatabaseTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 56.41 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 22
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 10 10 1
A testUsingCustomTable() 12 12 1
A prepareDatabase() 0 5 2

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
require_once 'BaseDatabase.php';
4
5
/**
6
 * @requires extension pdo_sqlite
7
 */
8
class SqliteDatabaseTest extends BaseDatabase
9
{
10
    protected $path = ':memory:';
11
12
    /**
13
     * @var \ByJG\DbMigration\Migration
14
     */
15
    protected $migrate = null;
16
17 View Code Duplication
    public function setUp()
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...
18
    {
19
        # Dump SQLite database.
20
        $this->prepareDatabase();
21
22
        $uri = new \ByJG\Util\Uri("sqlite://{$this->path}");
23
        $this->migrate = new \ByJG\DbMigration\Migration($uri, __DIR__ . '/../example/sqlite', true, $this->migrationTable);
24
        $this->migrate->registerDatabase("sqlite", \ByJG\DbMigration\Database\SqliteDatabase::class);
25
        parent::setUp();
26
    }
27
28 View Code Duplication
    public function testUsingCustomTable()
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...
29
    {
30
        $this->migrationTable = 'migration_table';
31
32
        $this->prepareDatabase();
33
34
        $uri = new \ByJG\Util\Uri("sqlite://{$this->path}");
35
        $this->migrate = new \ByJG\DbMigration\Migration($uri, __DIR__ . '/../example/sqlite', true, $this->migrationTable);
36
        $this->migrate->registerDatabase("sqlite", \ByJG\DbMigration\Database\SqliteDatabase::class);
37
38
        parent::testUpVersion1();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (testUpVersion1() instead of testUsingCustomTable()). Are you sure this is correct? If so, you might want to change this to $this->testUpVersion1().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
39
    }
40
41
    protected function prepareDatabase() {
42
        if ($this->path != ":memory:") {
43
            file_put_contents($this->path, '');
44
        }
45
    }
46
}
47