LoggerAdapter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 52
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 4
A up() 0 11 1
A isTable() 0 3 1
A checkLog() 0 13 1
A writeLog() 0 3 1
1
<?php
2
3
namespace App\Ship\Utils\Database;
4
5
use Rudra\Model\QBFacade;
6
use Rudra\Container\Facades\Rudra;
7
use App\Ship\Utils\Database\Driver\MySQL;
8
use App\Ship\Utils\Database\Driver\PgSQL;
9
use App\Ship\Utils\Database\Driver\SQLite;
10
11
class LoggerAdapter
12
{
13
    protected $driver;
14
    protected string $table;
15
16
    public function __construct()
17
    {
18
        if (Rudra::get("DSN")->getAttribute(\PDO::ATTR_DRIVER_NAME) === "mysql") {
19
            $this->driver = new MySQL($this->table);
20
        } elseif (Rudra::get("DSN")->getAttribute(\PDO::ATTR_DRIVER_NAME) === "pgsql") {
21
            $this->driver = new PgSQL($this->table);
22
        } elseif (Rudra::get("DSN")->getAttribute(\PDO::ATTR_DRIVER_NAME) === "sqlite") {
23
            $this->driver = new SQLite($this->table);
24
        }
25
    }
26
27
    public function up(): void
28
    {
29
        $query = QBFacade::create($this->table)
30
            ->integer('id', '', true)
31
            ->string('name')
32
            ->created_at()
33
            ->pk('id')
34
            ->close()
35
            ->get();
36
37
        Rudra::get("DSN")->prepare("$query")->execute();
38
    }
39
40
    public function isTable()
41
    {
42
        return $this->driver->isTable();
43
    }
44
45
    public function writeLog(string $name): void
46
    {
47
        $this->driver->writeLog($name);
48
    }
49
50
    public function checkLog(string $name)
51
    {
52
        $stmt = Rudra::get("DSN")->prepare(QBFacade::select()
53
            ->from($this->table)
54
            ->where('name = :name')
55
            ->get()
56
        );
57
58
        $stmt->execute([
59
            ':name' => $name,
60
        ]);
61
62
        return $stmt->fetch(\PDO::FETCH_ASSOC);
63
    }
64
}
65