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

PgSQL   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A writeLog() 0 10 1
A isTable() 0 11 1
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