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

SQLiteDriver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 60
ccs 27
cts 27
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B getTable() 0 32 4
A showTables() 0 4 1
1
<?php
2
3
namespace Rougin\Describe\Driver;
4
5
use PDO;
6
use Rougin\Describe\Driver\DriverInterface;
7
use Rougin\Describe\Column;
8
9
/**
10
 * SQLite Driver
11
 *
12
 * A database driver extension for SQLite.
13
 * 
14
 * @package  Describe
15
 * @category Driver
16
 * @author   Rougin Royce Gutib <[email protected]>
17
 */
18
class SQLiteDriver implements DriverInterface
19
{
20
    protected $pdo;
21
22
    /**
23
     * @param PDO $pdo
24
     */
25 15
    public function __construct(PDO $pdo)
26
    {
27 15
        $this->pdo = $pdo;
28 15
    }
29
30
    /**
31
     * Returns the result.
32
     * 
33
     * @return array
34
     */
35 12
    public function getTable($table)
36
    {
37 12
        $columns = [];
38
39 12
        $information = $this->pdo->prepare(
40 12
            'PRAGMA table_info("' . $table . '");'
41 12
        );
42
43 12
        $information->execute();
44 12
        $information->setFetchMode(PDO::FETCH_OBJ);
45
46 12
        while ($row = $information->fetch()) {
47 12
            $column = new Column;
48
49 12
            if ( ! $row->notnull) {
50 12
                $column->setNull(TRUE);
51 12
            }
52
53 12
            if ($row->pk) {
54 12
                $column->setPrimary(TRUE);
55 12
                $column->setAutoIncrement(TRUE);
56 12
            }
57
58 12
            $column->setDefaultValue($row->dflt_value);
59 12
            $column->setField($row->name);
60 12
            $column->setDataType(strtolower($row->type));
61
62 12
            array_push($columns, $column);
63 12
        }
64
65 12
        return $columns;
66
    }
67
68
    /**
69
     * Shows the list of tables.
70
     * 
71
     * @return array
72
     */
73 3
    public function showTables()
74
    {
75 3
        return [];
76
    }
77
}
78