Completed
Push — master ( 0eeb04...4002ae )
by Oscar
02:31
created

Sqlite   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTables() 0 4 1
A getTableFields() 0 20 2
1
<?php
2
3
namespace SimpleCrud\Scheme;
4
5
use PDO;
6
7
/**
8
 * Class to retrieve info from a sqlite database.
9
 */
10
class Sqlite extends Scheme
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected function getTables()
16
    {
17
        return $this->db->execute('SELECT name FROM sqlite_master WHERE (type="table" OR type="view") AND name != "sqlite_sequence"')->fetchAll(PDO::FETCH_COLUMN, 0);
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function getTableFields($table)
24
    {
25
        $result = $this->db->execute("pragma table_info(`{$table}`)")->fetchAll(PDO::FETCH_ASSOC);
26
        $fields = [];
27
28
        foreach ($result as $field) {
29
            $name = $field['name'];
30
31
            $fields[$name] = [
32
                'type' => strtolower($field['type']),
33
                'null' => ($field['notnull'] !== '1'),
34
                'default' => $field['dflt_value'],
35
                'unsigned' => null,
36
                'length' => null,
37
                'values' => null,
38
            ];
39
        }
40
41
        return $fields;
42
    }
43
}
44