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

SQLiteDriver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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