Completed
Pull Request — master (#1)
by Rougin
07:32
created

CodeIgniterDriver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 8.93 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 5
loc 56
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 5 23 4
A getTable() 0 4 1
A showTables() 0 4 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 Rougin\Describe\Driver;
4
5
/**
6
 * CodeIgniter Driver
7
 *
8
 * A database driver specifically used for CodeIgniter.
9
 *
10
 * @package  Describe
11
 * @category Driver
12
 * @author   Rougin Royce Gutib <[email protected]>
13
 */
14
class CodeIgniterDriver implements DriverInterface
15
{
16
    /**
17
     * @var \Rougin\Describe\Driver\DriverInterface|null
18
     */
19
    protected $driver = null;
20
21
    /**
22
     * Gets the specified driver from the specified database connection.
23
     *
24
     * @param array $database
25
     */
26 18
    public function __construct(array $database)
27
    {
28 18
        $mysql  = [ 'mysql', 'mysqli' ];
29 18
        $sqlite = [ 'pdo', 'sqlite', 'sqlite3' ];
30
31
        // NOTE: To be removed in v1.0.0
32 18
        if (isset($database['default'])) {
33 18
            $database = $database['default'];
34 18
        }
35
36 18
        if (in_array($database['dbdriver'], $mysql)) {
37 9
            $dsn = 'mysql:host=' . $database['hostname'] . ';dbname=' . $database['database'];
38 9
            $pdo = new \PDO($dsn, $database['username'], $database['password']);
39
40
            $this->driver = new MySQLDriver($pdo, $database['database']);
41
        }
42
43 9 View Code Duplication
        if (in_array($database['dbdriver'], $sqlite)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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 9
            $pdo = new \PDO($database['hostname']);
45
46 9
            $this->driver = new SQLiteDriver($pdo);
47 9
        }
48 9
    }
49
50
    /**
51
     * Returns the result.
52
     *
53
     * @return array
54
     */
55 6
    public function getTable($table)
56
    {
57 6
        return $this->driver->getTable($table);
58
    }
59
60
    /**
61
     * Shows the list of tables.
62
     *
63
     * @return array
64
     */
65 3
    public function showTables()
66
    {
67 3
        return $this->driver->showTables();
68
    }
69
}
70