Completed
Push — master ( 471540...e3dcd8 )
by Rasmus
03:02
created

MySQLDatabase   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 0 Features 4
Metric Value
wmc 7
c 7
b 0
f 4
lcom 0
cbo 3
dl 0
loc 73
ccs 20
cts 20
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 12 1
A createConnection() 0 4 1
A quoteName() 0 4 1
A select() 0 4 1
A insert() 0 4 1
A update() 0 4 1
A delete() 0 4 1
1
<?php
2
3
namespace mindplay\sql\mysql;
4
5
use mindplay\sql\model\Database;
6
use mindplay\sql\model\DatabaseContainer;
7
use mindplay\sql\model\Driver;
8
use mindplay\sql\model\query\DeleteQuery;
9
use mindplay\sql\model\query\InsertQuery;
10
use mindplay\sql\model\query\UpdateQuery;
11
use mindplay\sql\model\schema\Table;
12
use mindplay\sql\model\types\BoolType;
13
use mindplay\sql\model\types\FloatType;
14
use PDO;
15
16
class MySQLDatabase extends Database implements Driver
17
{
18 1
    protected function bootstrap(DatabaseContainer $container)
19
    {
20 1
        $container->set(Driver::class, $this);
21
22 1
        $container->register(BoolType::class, function () {
23 1
            return BoolType::get(1, 0);
24 1
        });
25
26 1
        $container->alias("scalar.boolean", BoolType::class);
27
28 1
        $container->register("scalar.double", FloatType::class);
29 1
    }
30
    
31
    /**
32
     * @param PDO $pdo
33
     * 
34
     * @return MySQLConnection
35
     */
36 1
    public function createConnection(PDO $pdo)
37
    {
38 1
        return $this->container->create(MySQLConnection::class, ['pdo' => $pdo]);
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44 1
    public function quoteName($name)
45
    {
46 1
        return '`' . $name . '`';
47
    }
48
    
49
    /**
50
     * @param Table $from
51
     *
52
     * @return MySQLSelectQuery
53
     */
54 1
    public function select(Table $from)
55
    {
56 1
        return $this->container->create(MySQLSelectQuery::class, ['root' => $from]);
57
    }
58
59
    /**
60
     * @param Table $into
61
     *
62
     * @return InsertQuery
63
     */
64 1
    public function insert(Table $into)
65
    {
66 1
        return $this->container->create(InsertQuery::class, ['table' => $into]);
67
    }
68
69
    /**
70
     * @param Table $table
71
     *
72
     * @return UpdateQuery
73
     */
74 1
    public function update(Table $table)
75
    {
76 1
        return $this->container->create(UpdateQuery::class, ['root' => $table]);
77
    }
78
79
    /**
80
     * @param Table $table
81
     *
82
     * @return DeleteQuery
83
     */
84 1
    public function delete(Table $table)
85
    {
86 1
        return $this->container->create(DeleteQuery::class, ['root' => $table]);
87
    }
88
}
89