Completed
Push — master ( ec2154...751b89 )
by Rougin
04:27
created

CodeIgniterDriver::showTables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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