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

MysqlConnection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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