Completed
Push — master ( 82f5a7...816810 )
by James Ekow Abaka
06:28
created

Db   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 42
rs 10

4 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
1
<?php
2
3
namespace ntentan\atiaa;
4
5
class Db
6
{
7
    private static $db;
8
    private static $defaultSettings;
9
    
10
    public static function getDriver()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
11
    {
12
        if(self::$db == null) {
13
            self::$db = \ntentan\atiaa\Driver::getConnection(self::$defaultSettings);
14
            self::$db->setCleanDefaults(true);
15
16
            try {
17
                self::$db->getPDO()->setAttribute(\PDO::ATTR_AUTOCOMMIT, false);
18
            } catch (\PDOException $e) {
19
                // Just do nothing for drivers which do not allow turning off autocommit
20
            }
21
        }
22
        return self::$db;
23
    }    
24
    
25
    /**
26
     * Set the settings used for creating default datastores.
27
     * @param array $settings
28
     */
29
    public static function setDefaultSettings($settings)
30
    {
31
        self::$defaultSettings = $settings;
32
    }    
33
    
34
    public static function getDefaultSettings()
35
    {
36
        return self::$defaultSettings;
37
    }
38
    
39
    public static function reset()
40
    {
41
        if(self::$db !== null) {
42
            self::$db->disconnect();
43
            self::$db = null;
44
        }
45
    }    
46
}
47