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

DbContext   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 76.47%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 37
ccs 13
cts 17
cp 0.7647
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getDriver() 0 3 1
A getDriverClassName() 0 8 2
A query() 0 3 1
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