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

Db::reset()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
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