Completed
Push — master ( 59d673...8b9586 )
by James Ekow Abaka
05:46
created

DbContext   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 75%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 0
cbo 6
dl 0
loc 35
ccs 12
cts 16
cp 0.75
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 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 $container;
12
13 33
    public function __construct(Container $container, $config = null) {
14 33
        if ($config) {
15 33
            Config::set('ntentan:db', $config);
16 33
            $container->bind(Driver::class)
17 33
                ->to(self::getDriverClassName(Config::get('ntentan:db.driver')));
18
        }
19 33
        $this->container = $container;
20 33
    }
21
22
    /**
23
     * 
24
     * @return Driver
25
     */
26 33
    public function getDriver() {
27 33
        return $this->container->singleton(Driver::class);
28
    }
29
30 33
    public static function getDriverClassName($driver) {
31 33
        if ($driver == null) {
32
            throw new exceptions\DatabaseDriverException(
33
            "Please provide a valid driver name in your database config file"
34
            );
35
        }
36 33
        return '\ntentan\atiaa\drivers\\' . Text::ucamelize($driver) . "Driver";
37
    }
38
39
    public function query($query, $bindData = false) {
40
        return $this->getDriver()->query($query, $bindData);
0 ignored issues
show
Documentation introduced by
$bindData is of type boolean, but the function expects a false|array<integer,*>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
    }
42
43
}
44