Passed
Push — main ( cc7f20...551104 )
by Pranjal
04:39 queued 02:46
created

Database   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 49
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getDB() 0 3 1
A connect() 0 11 2
A create() 0 3 1
A delete() 0 2 1
A get() 0 3 1
A exec() 0 3 1
A find() 0 3 1
A getOne() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Scrawler\Arca\Facade;
5
6
use Scrawler\Arca\Manager\TableManager;
7
use Scrawler\Arca\Manager\RecordManager;
8
use Scrawler\Arca\Manager\ModelManager;
9
use Scrawler\Arca\Database as DB;
10
11
class Database
12
{
13
    private static $database;
14
15
    public static function connect(array $connectionParams)
16
    {
17
18
        if (self::$database == null) {
19
            $connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
20
            self::$database = new DB($connection);
21
            self::$database->setManagers(new TableManager(self::$database), new RecordManager(self::$database), new ModelManager(self::$database));
22
            return self::$database;
23
        }
24
25
        return self::$database;
26
    }
27
28
    private static function getDB()
29
    {
30
        return self::$database;
31
    }
32
33
    public static function create($name)
34
    {
35
        return self::getDB()->create($name);
36
    }
37
38
    public static function get($table, $id)
39
    {
40
        return self::getDB()->get($table, $id);
41
    }
42
43
    public static function getOne($table, $id)
44
    {
45
        return self::getDB()->getOne($table, $id);
46
    }
47
48
    public static function exec($sql)
49
    {
50
        return self::getDB()->exec($sql);
51
    }
52
53
    public static function delete($model){
54
        return self::getDB()->delete($model);
55
    }
56
57
    public static function find($table, $id)
58
    {
59
        return self::getDB()->find($table, $id);
60
    }
61
62
63
}