Completed
Push — master ( dbcbc1...04d817 )
by Sébastien
02:01
created

MysqlConnection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 53
wmc 6
lcom 1
cbo 1
ccs 13
cts 14
cp 0.9286
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCurrentSchema() 0 13 4
A getResource() 0 3 1
1
<?php
2
3
namespace Soluble\DbWrapper\Connection;
4
5
use Soluble\DbWrapper\Adapter\AdapterInterface;
6
7
class MysqlConnection implements ConnectionInterface
8
{
9
10
    /**
11
     *
12
     * @var AdapterInterface
13
     */
14
    protected $adapter;
15
    
16
    
17
    /**
18
     *
19
     * @var mixed
20
     */
21
    protected $resource;
22
    
23
    /**
24
     * 
25
     * @param AdapterInterface $adapter
26
     * @param mixed $resource
27
     */
28 13
    public function __construct(AdapterInterface $adapter, $resource)
29
    {
30 13
        $this->adapter = $adapter;
31 13
        $this->resource = $resource;
32 13
    }
33
    
34
    /**
35
     * {@inheritdoc}
36
     */
37 2
    public function getCurrentSchema()
38
    {
39 2
        $query = 'SELECT DATABASE() as current_schema';
40
        try {
41 2
            $results = $this->adapter->query($query);
42 2
            if (count($results) == 0 || $results[0]['current_schema'] === null) {
43 2
                return false;
44
            }
45 2
        } catch (\Exception $e) {
46
            throw new Exception\RuntimeException($e->getMessage());
47
        }
48 2
        return $results[0]['current_schema'];
49
    }
50
    
51
    /**
52
     * {@inheritdoc}
53
     * @return \mysqli|\PDO
54
     */
55 2
    public function getResource() {
56 2
        return $this->resource;    
57
    }
58
    
59
}
60
61