Passed
Push — master ( 705452...770324 )
by Mathieu
35:33 queued 25:29
created

MigrationModelList   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDBConfig() 0 4 1
A loadAllWithConfig() 0 14 1
A connectDB() 0 6 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Suricate\Migrations;
6
7
use Suricate\DBCollection;
8
use Suricate\Suricate;
9
10
class MigrationModelList extends DBCollection
11
{
12
    protected $tableName = 'suricate_migrations';
13
    protected $itemsType = MigrationModel::class;
14
15
    public function setDBConfig(string $config): self 
16
    {
17
        $this->DBConfig = $config;
18
        return $this;
19
    }
20
21
    public static function loadAllWithConfig(string $configName)
22
    {
23
        $calledClass = new self();
24
        $collection = new $calledClass();
25
        $collection->setDBConfig($configName);
26
27
        $sqlParams = [];
28
29
        $sql = "SELECT *";
30
        $sql .= "   FROM `" . $collection->getTableName() . "`";
31
32
        $collection->loadFromSql($sql, $sqlParams);
33
34
        return $collection;
35
    }
36
37
    protected function connectDB()
38
    {
39
        if (!$this->dbLink) {
40
            $this->dbLink = Suricate::Database(true);
41
            if ($this->getDBConfig() !== '') {
42
                $this->dbLink->setConfig($this->getDBConfig());
43
            }
44
            
45
        }
46
    }
47
}
48