Completed
Push — master ( 3a6993...a409ac )
by James Ekow Abaka
01:53
created

DbContext::getDriver()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
namespace ntentan\atiaa;
4
5
use ntentan\panie\Container;
6
use ntentan\utils\Text;
7
8
class DbContext {
9
10
    private $container;
11
    private $config;
12
    private $driver;
13
14 33
    public function __construct(Container $container, array $config) {
15 33
        $container->bind(Driver::class)
16 33
            ->to(self::getDriverClassName($config['driver']));
17 33
        $this->container = $container;
18 33
        $this->config = $config;
19 33
    }
20
21
    /**
22
     * 
23
     * @return Driver
24
     */
25 33
    public function getDriver() {
26 33
        if(is_null($this->driver)) {
27 33
            $this->driver = $this->container->resolve(Driver::class, ['config' => $this->config]);
28
        }
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) {
42
        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...
43
    }
44
45
}
46