Completed
Push — master ( bd6b93...2911b9 )
by Rougin
02:46
created

CodeIgniterDriver   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 64.29%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 9
c 3
b 0
f 1
lcom 1
cbo 2
dl 0
loc 69
ccs 18
cts 28
cp 0.6429
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B getDriver() 0 23 6
A getTable() 0 6 1
A showTables() 0 4 1
1
<?php
2
3
namespace Rougin\Describe\Driver;
4
5
use PDO;
6
use Rougin\Describe\Column;
7
use Rougin\Describe\Driver\MySQLDriver;
8
use Rougin\Describe\Driver\SQLiteDriver;
9
use Rougin\Describe\Driver\DriverInterface;
10
11
/**
12
 * CodeIgniter Driver
13
 *
14
 * A database driver specifically used for CodeIgniter.
15
 * 
16
 * @package  Describe
17
 * @category Driver
18
 * @author   Rougin Royce Gutib <[email protected]>
19
 */
20
class CodeIgniterDriver implements DriverInterface
21
{
22
    protected $connection;
23
    protected $database;
24
    protected $driver;
25
26
    /**
27
     * @param array  $database
28
     * @param string $connection
29
     */
30 9
    public function __construct(array $database, $connection = 'default')
31
    {
32 9
        $this->database = $database;
33 9
        $this->connection = $connection;
34 9
    }
35
36
    /**
37
     * Gets the specified driver from the specified database connection.
38
     * 
39
     * @param  array  $database
40
     * @param  string $connection
41
     * @return \Rougin\Describe\Driver\DriverInterface
42
     */
43 6
    public function getDriver(array $database, $connection)
44
    {
45 6
        switch ($database[$connection]['dbdriver']) {
46 6
            case 'mysql':
47 6
            case 'mysqli':
48
                $database = $database[$connection]['database'];
49
50
                $pdo = new PDO(
51
                    'mysql:host=' . $database[$connection]['hostname'] .
52
                    ';dbname=' . $database[$connection]['database'],
53
                    $database[$connection]['username'],
54
                    $database[$connection]['password']
55
                );
56
57
                return new MySQLDriver($pdo, $database);
58 6
            case 'pdo':
59 6
            case 'sqlite':
60 6
            case 'sqlite3':
61 6
                $pdo = new PDO($database[$connection]['hostname']);
62
63 6
                return new SQLiteDriver($pdo);
64
        }
65
    }
66
67
    /**
68
     * Returns the result.
69
     * 
70
     * @return array
71
     */
72 6
    public function getTable($table)
73
    {
74 6
        $driver = $this->getDriver($this->database, $this->connection);
75
76 6
        return $driver->getTable($table);
77
    }
78
79
    /**
80
     * Shows the list of tables.
81
     * 
82
     * @return array
83
     */
84 3
    public function showTables()
85
    {
86 3
        return [];
87
    }
88
}
89