Completed
Push — master ( fb8d74...ff1e54 )
by Sébastien
02:09
created

AbstractMysqlConnection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4286
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Soluble\DbWrapper\Connection\Mysql;
4
5
abstract class AbstractMysqlConnection
6
{
7
    /**
8
     *
9
     * @var \Soluble\DbWrapper\Adapter\AdapterInterface
10
     */
11
    protected $adapter;
12
13
    /**
14
     *
15
     * @param AdapterInterface $adapter
16
     * @param mixed $resource
17
     */
18
    public function __construct(AdapterInterface $adapter, $resource)
19
    {
20
        $this->adapter = $adapter;
0 ignored issues
show
Documentation Bug introduced by
It seems like $adapter of type object<Soluble\DbWrapper...Mysql\AdapterInterface> is incompatible with the declared type object<Soluble\DbWrapper...apter\AdapterInterface> of property $adapter.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
21
        $this->resource = $resource;
0 ignored issues
show
Bug introduced by
The property resource does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
    }
23
24
25
    /**
26
     * Return current schema/database name
27
     * @throws \Soluble\DbWrapper\Exception\RuntimeException
28
     * @return string|false
29
     */
30 2
    public function getCurrentSchema()
31
    {
32 2
        $query = 'SELECT DATABASE() as current_schema';
33
        try {
34 2
            $results = $this->adapter->query($query);
35 2
            if (count($results) == 0 || $results[0]['current_schema'] === null) {
36 2
                return false;
37
            }
38 2
        } catch (\Exception $e) {
39
            throw new Exception\RuntimeException($e->getMessage());
40
        }
41 2
        return $results[0]['current_schema'];
42
    }
43
}
44