Completed
Push — master ( f42128...f70f0b )
by James Ekow Abaka
01:39
created

DbContext::destroy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
namespace ntentan\atiaa;
4
5
use ntentan\panie\Container;
6
use ntentan\utils\Text;
7
8
class DbContext
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
9
{
10
11
    private $driver;
12
    private $driverFactory;
13
    private static $instance;
14
15
    private function __construct(DriverFactory $driverFactory)
16
    {
17
        $this->driverFactory = $driverFactory;
18
        self::$instance = $this;
19
    }
20
21
    public static function initialize(DriverFactory $driverFactory)
22
    {
23
        self::$instance = new self($driverFactory);
24
        return self::$instance;
25
    }
26
27
    public static function getInstance(): DbContext
28
    {
29
        if(!self::$instance) {
30
            throw new \Exception("The database context has not been initialized");  
31
        }
32
        return self::$instance;
33
    }
34
35
    /**
36
     *
37
     * @return Driver
38
     */
39
    public function getDriver() : Driver
40
    {
41
        if (is_null($this->driver)) {
42
            $this->driver = $this->driverFactory->createDriver();
43
            $this->driver->connect();
44
        }
45
        return $this->driver;
46
    }
47
48
    public function query($query, $bindData = false)
49
    {
50
        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...
51
    }
52
53
    public static function destroy()
54
    {
55
        self::$instance->getDriver()->disconnect();
56
        self::$instance = null;
57
    }
58
59
}
60