Connect::__clone()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace CodeWdev\TableGenerator;
4
5
use PDO;
6
use PDOException;
7
8
9
/**
10
 *
11
 */
12
class Connect
13
{
14
    /** @var PDO */
15
    private static $instance;
16
17
    /** @var PDOException */
18
    private static $error;
19
20
    /**
21
     * @return PDO
22
     */
23
    public static function getInstance(): ?PDO
24
    {
25
        if (empty(self::$instance)) {
26
            try {
27
                self::$instance = new PDO(
28
                    TABLE_GEN_CONF["driver"] . ":host=" . TABLE_GEN_CONF["host"] . ";dbname=" . TABLE_GEN_CONF["dbname"] . ";port=" . TABLE_GEN_CONF["port"],
29
                    TABLE_GEN_CONF["username"],
30
                    TABLE_GEN_CONF["passwd"],
31
                    TABLE_GEN_CONF["options"]
32
                );
33
            } catch (PDOException $exception) {
34
                self::$error = $exception;
35
            }
36
        }
37
        return self::$instance;
38
    }
39
40
41
    /**
42
     * @return PDOException|null
43
     */
44
    public static function getError(): ?PDOException
45
    {
46
        return self::$error;
47
    }
48
49
    /**
50
     * Connect constructor.
51
     */
52
    private function __construct()
53
    {
54
    }
55
56
    /**
57
     * Connect clone.
58
     */
59
    private function __clone()
60
    {
61
    }
62
}
63