Completed
Push — master ( a30b0b...f1bafc )
by Sébastien
02:18
created

MysqlCommonTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
query() 0 1 ?
A getCurrentSchema() 0 13 4
1
<?php
2
3
namespace Soluble\DbWrapper\Adapter\Mysql;
4
5
use Soluble\DbWrapper\Exception;
6
7
trait MysqlCommonTrait
8
{
9
    
10
    /**
11
     * Execute query and return query as an ArrayObject
12
     *
13
     * @throws \Soluble\DbWrapper\Exception\InvalidArgumentException
14
     * @param string $query
15
     * @return \Soluble\DbWrapper\Result\Resultset
16
     */    
17
    abstract public function query($query);
18
19
    /**
20
     * Return current schema/database name
21
     * 
22
     * @throws \Soluble\DbWrapper\Exception\RuntimeException
23
     * @return string|false
24
     */
25 2
    public function getCurrentSchema()
26
    {
27 2
        $query = 'SELECT DATABASE() as current_schema';
28
        try {
29 2
            $results = $this->query($query);
30 2
            if (count($results) == 0 || $results[0]['current_schema'] === null) {
31 2
                return false;
32
            }
33 2
        } catch (\Exception $e) {
34
            throw new Exception\RuntimeException($e->getMessage());
35
        }
36 2
        return $results[0]['current_schema'];
37
    }
38
}
39