Completed
Push — master ( 6460ce...1729d3 )
by James Ekow Abaka
05:20
created

DbContext   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 73.32%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 34
ccs 11
cts 15
cp 0.7332
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
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\panie\Container;
6
use ntentan\utils\Text;
7
8
class DbContext {
9
10
    private $container;
11
    private $config;
12
13 33
    public function __construct(Container $container, array $config) {
14 33
        $container->bind(Driver::class)
15 33
            ->to(self::getDriverClassName($config['driver']));
16 33
        $this->container = $container;
17 33
        $this->config = $config;
18 33
    }
19
20
    /**
21
     * 
22
     * @return Driver
23
     */
24 33
    public function getDriver() {
25 33
        return $this->container->singleton(Driver::class, ['config' => $this->config]);
26
    }
27
28 33
    public static function getDriverClassName($driver) {
29 33
        if ($driver == null) {
30
            throw new exceptions\DatabaseDriverException(
31
            "Please provide a valid driver name in your database config file"
32
            );
33
        }
34 33
        return '\ntentan\atiaa\drivers\\' . Text::ucamelize($driver) . "Driver";
35
    }
36
37
    public function query($query, $bindData = false) {
38
        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...
39
    }
40
41
}
42