Completed
Push — master ( 751b89...996652 )
by Rougin
04:25
created

CodeIgniterDriver::__construct()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 19
cts 19
cp 1
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 16
nc 12
nop 1
crap 7
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
        // NOTE: To be removed in v1.0.0
29 18
        if (isset($database['default'])) {
30 18
            $database = $database['default'];
31 18
        }
32
33 18
        switch ($database['dbdriver']) {
34 18
            case 'mysql':
35 18
            case 'mysqli':
36 9
                $dsn = 'mysql:host=' . $database['hostname'] . ';dbname=' . $database['database'];
37 9
                $pdo = new \PDO($dsn, $database['username'], $database['password']);
38
39 9
                $this->driver = new MySQLDriver($pdo, $database['database']);
40
41 9
                break;
42 9
            case 'pdo':
43 9
            case 'sqlite':
44 9
            case 'sqlite3':
45 9
                $pdo = new \PDO($database['hostname']);
46
47 9
                $this->driver = new SQLiteDriver($pdo);
48
49 9
                break;
50 18
        }
51 18
    }
52
53
    /**
54
     * Returns the result.
55
     *
56
     * @return array
57
     */
58 12
    public function getTable($table)
59
    {
60 12
        return $this->driver->getTable($table);
61
    }
62
63
    /**
64
     * Shows the list of tables.
65
     *
66
     * @return array
67
     */
68 6
    public function showTables()
69
    {
70 6
        return $this->driver->showTables();
71
    }
72
}
73