DbManager::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
ccs 3
cts 3
cp 1
cc 1
nc 1
nop 0
crap 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