Completed
Push — master ( e8f4cf...5c9c14 )
by James Ekow Abaka
05:22
created

Db   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 35.29%

Importance

Changes 6
Bugs 2 Features 3
Metric Value
wmc 7
c 6
b 2
f 3
lcom 0
cbo 5
dl 0
loc 44
ccs 6
cts 17
cp 0.3529
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getDriver() 0 4 1
A getDefaultDriverClassName() 0 4 1
A getDriverClassName() 0 9 2
A reset() 0 4 1
A getConnection() 0 5 1
A query() 0 4 1
1
<?php
2
3
namespace ntentan\atiaa;
4
5
use ntentan\config\Config;
6
use ntentan\panie\InjectionContainer;
7
use ntentan\utils\Text;
8
9
class Db
10
{
11
    //private static $db;
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
12
    
13
    /**
14
     * 
15
     * @return Driver
16
     */
17
    public static function getDriver()
18
    {
19
        return InjectionContainer::singleton(Driver::class);
20
    }
21
    
22
    public static function getDefaultDriverClassName()
23
    {
24
        return self::getDriverClassName(Config::get('ntentan:db.driver'));
25
    }
26
    
27 33
    private static function getDriverClassName($driver)
28
    {
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 static function reset()
38
    {
39
        self::getDriver()->disconnect();
40
    }    
41
    
42 33
    public static function getConnection($parameters)
43
    {
44 33
        Config::set('ntentan:db', $parameters);
45 33
        return InjectionContainer::resolve(self::getDriverClassName($parameters['driver']));
46
    }
47
    
48
    public static function query($query, $bindData = false)
49
    {
50
        return self::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...
51
    }
52
}
53