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

MysqlCommonTrait::getCurrentSchema()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0313

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 13
ccs 7
cts 8
cp 0.875
rs 9.2
nc 4
cc 4
eloc 9
nop 0
crap 4.0313
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