Connect   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 32
rs 10
c 1
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 15 3
A migrationTable() 0 7 2
1
<?php
2
3
namespace Luke\Migration\Config\Database;
4
5
use PDO;
6
use PDOException;
7
8
class Connect
9
{
10
    private static ?PDO $instance;
11
12
    private static function getInstance(): ?PDO
13
    {
14
        if (empty(self::$instance)) {
15
            try {
16
                self::$instance = new \PDO(
17
                    "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME,
18
                    DB_USER,
19
                    DB_PASSWD,
20
                    DB_OPTIONS
21
                );
22
            } catch (\PDOException $exception) {
23
                throw new \PDOException($exception->getMessage(), (int)$exception->getCode());
24
            }
25
        }
26
        return self::$instance;
27
    }
28
29
30
    /**
31
     * @throws Exception
32
     */
33
    public static function migrationTable(string $tableCreated)
34
    {
35
        try {
36
            $stmt = self::getInstance()->prepare($tableCreated);
37
            $stmt->execute();
38
        } catch (PDOException $e) {
39
            throw new PDOException($e->getMessage());
40
        }
41
    }
42
}
43