DbManager   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 9
c 1
b 0
f 0
dl 0
loc 25
rs 10
ccs 9
cts 9
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 6 1
A init() 0 5 1
1
<?php
2
namespace RazonYang\Yii2\Setting;
3
4
use yii\db\Connection;
5
use yii\di\Instance;
6
use yii\helpers\ArrayHelper;
7
8
class DbManager extends Manager
9
{
10
    /**
11
     * @var Connection $db
12
     */
13
    public $db = 'db';
14
15
    /**
16
     * @var string $modelClass
17
     */
18
    public $settingTable = '{{%setting}}';
19
20 1
    public function init()
21
    {
22 1
        parent::init();
23
24 1
        $this->db = Instance::ensure($this->db, Connection::class);
25 1
    }
26
27 1
    public function load(): array
28
    {
29 1
        $tableName = $this->db->quoteTableName($this->settingTable);
30 1
        $sql = "SELECT id, value FROM $tableName";
31 1
        $rows = $this->db->createCommand($sql)->queryAll();
32 1
        return ArrayHelper::map($rows, 'id', 'value');
33
    }
34
}
35