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

DbContext::getDriverClassName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 3
cts 5
cp 0.6
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2.2559
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