Passed
Push — master ( 2d63f5...f4d34a )
by Korotkov
13:30 queued 11:37
created

PgSQL::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
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 1
dl 0
loc 1
rs 10
1
<?php
2
3
namespace App\Ship\Utils\Database\Driver;
4
5
use Rudra\Container\Facades\Rudra;
6
7
class PgSQL
8
{
9
    public function __construct(protected $table){}
10
11
    public function isTable()
12
    {
13
        $query = Rudra::get("DSN")->query("
14
        SELECT EXISTS (
15
            SELECT FROM information_schema.tables 
16
            WHERE  table_schema = 'public'
17
            AND    table_name   = '{$this->table}'
18
            );
19
        ");
20
21
        return $query->fetchColumn();
22
    }
23
24
    public function writeLog(string $name): void
25
    {
26
        $query = Rudra::get("DSN")->prepare("
27
            INSERT INTO {$this->table} (name, created_at)
28
            VALUES (:name, :created_at)"
29
        );
30
31
        $query->execute([
32
            ':name' => $name,
33
            ':created_at' => date('d-M-Y H:i:s')
34
        ]);
35
    }
36
}
37