Completed
Push — master ( 3c43e5...59d673 )
by James Ekow Abaka
08:14
created

DbContext::query()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace ntentan\atiaa;
4
5
use ntentan\config\Config;
6
use ntentan\panie\Container;
7
use ntentan\utils\Text;
8
9
class DbContext {
10
11
    private $driver;
12
    private $container;
13
14 33
    public function __construct(Container $container, $config = null) {
15 33
        if ($config) {
16 33
            Config::set('ntentan:db', $config);
17 33
            $container->bind(Driver::class)
18 33
                ->to(self::getDriverClassName(Config::get('ntentan:db.driver')));
19
        }
20 33
        $this->driver = $container->resolve(Driver::class);
21 31
        $this->container = $container;
22 31
    }
23
24
    /**
25
     * 
26
     * @return Driver
27
     */
28 31
    public function getDriver() {
29 31
        return $this->driver;
30
    }
31
32 33
    public static function getDriverClassName($driver) {
33 33
        if ($driver == null) {
34
            throw new exceptions\DatabaseDriverException(
35
            "Please provide a valid driver name in your database config file"
36
            );
37
        }
38 33
        return '\ntentan\atiaa\drivers\\' . Text::ucamelize($driver) . "Driver";
39
    }
40
41
    public function query($query, $bindData = false) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
42
        return $this->driver->query($query, $bindData);
43
    }
44
45
}
46