Completed
Push — master ( f2dd2e...a32d5e )
by James Ekow Abaka
07:50
created

Db   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 8
c 3
b 0
f 2
lcom 1
cbo 1
dl 0
loc 51
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDriver() 0 14 3
A setDefaultSettings() 0 4 1
A getDefaultSettings() 0 4 1
A reset() 0 7 2
A query() 0 4 1
1
<?php
2
3
namespace ntentan\atiaa;
4
5
class Db
6
{
7
    private static $db;
8
    private static $defaultSettings;
9
    
10
    /**
11
     * 
12
     * @return Driver
13
     */
14
    public static function getDriver()
15
    {
16
        if(self::$db == null) {
17
            self::$db = \ntentan\atiaa\Driver::getConnection(self::$defaultSettings);
18
            self::$db->setCleanDefaults(true);
19
20
            try {
21
                self::$db->getPDO()->setAttribute(\PDO::ATTR_AUTOCOMMIT, false);
22
            } catch (\PDOException $e) {
23
                // Just do nothing for drivers which do not allow turning off autocommit
24
            }
25
        }
26
        return self::$db;
27
    }    
28
    
29
    /**
30
     * Set the settings used for creating default datastores.
31
     * @param array $settings
32
     */
33
    public static function setDefaultSettings($settings)
34
    {
35
        self::$defaultSettings = $settings;
36
    }    
37
    
38
    public static function getDefaultSettings()
39
    {
40
        return self::$defaultSettings;
41
    }
42
    
43
    public static function reset()
44
    {
45
        if(self::$db !== null) {
46
            self::$db->disconnect();
47
            self::$db = null;
48
        }
49
    }    
50
    
51
    public static function query($query, $bindData = false)
52
    {
53
        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...
54
    }
55
}
56