Database   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 14
lcom 0
cbo 2
dl 0
loc 95
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A connect() 0 7 1
A size() 0 15 2
A select() 0 4 1
A update() 0 4 1
A statement() 0 4 1
A enableQueryLog() 0 4 1
A getLastQuery() 0 5 1
A connection() 0 4 1
A schema() 0 4 1
A table() 0 4 1
A beginTransaction() 0 4 1
A commit() 0 4 1
A rollback() 0 4 1
1
<?php namespace Tequilarapido\Database;
2
3
use Illuminate\Database\Capsule\Manager as Capsule;
4
5
class Database
6
{
7
8
    /**
9
     * Initialize Illuminate Database connection
10
     *
11
     * @param $dbConfig
12
     */
13
    public function connect($dbConfig)
14
    {
15
        $capsule = new Capsule;
16
        $capsule->addConnection($dbConfig);
17
        $capsule->bootEloquent();
18
        $capsule->setAsGlobal();
19
    }
20
21
22
    public function size($database)
23
    {
24
        $query = '';
25
        $query .= 'SELECT table_schema, Sum(data_length + index_length) as size ';
26
        $query .= 'FROM   information_schema.tables ';
27
        $query .= 'WHERE table_schema = ? ';
28
        $query .= 'GROUP BY table_schema';
29
30
        $res = static::select($query, array($database));
31
        if (!empty($res[0]['size'])) {
32
            return round($res[0]['size'] / 1024 / 1024);
33
        }
34
35
        return false;
36
    }
37
38
    //
39
    // Helpers
40
    //
41
42
    public static function select($query, $bindings = array())
43
    {
44
        return Capsule::connection()->select($query, $bindings);
45
    }
46
47
    public static function update($query, $bindings = array())
48
    {
49
        return Capsule::connection()->update($query, $bindings);
50
    }
51
52
    public static function statement($query, $bindings = array())
53
    {
54
        return Capsule::connection()->statement($query, $bindings);
55
    }
56
57
    public static function enableQueryLog()
58
    {
59
        Capsule::connection()->enableQueryLog();
60
    }
61
62
    public static function getLastQuery()
63
    {
64
        $queries = Capsule::connection()->getQueryLog();
65
        return end($queries);
66
    }
67
68
    public static function connection()
69
    {
70
        return Capsule::connection();
71
    }
72
73
    public static function schema()
74
    {
75
        return Capsule::schema();
76
    }
77
78
    public static function table($table)
79
    {
80
        return Capsule::table($table);
81
    }
82
83
    public static function beginTransaction()
84
    {
85
        return Capsule::connection()->beginTransaction();
86
    }
87
88
    public static function commit()
89
    {
90
        return Capsule::connection()->commit();
91
    }
92
93
    public static function rollback()
94
    {
95
        return Capsule::connection()->rollBack();
96
    }
97
98
99
}