EnumColumn   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataCellValue() 0 4 1
A init() 0 4 3
1
<?php
2
namespace backend\components\grid;
3
4
use yii\grid\DataColumn;
5
use yii\helpers\ArrayHelper;
6
7
class EnumColumn extends DataColumn
8
{
9
    /**
10
     * @var array List of value => name pairs
11
     */
12
    public $enum = [];
13
14
    /**
15
     * @var bool
16
     */
17
    public $loadFilterDefaultValues = true;
18
19
    /**
20
     * @inheritdoc
21
     */
22
    public function init()
23
    {
24
        if ($this->loadFilterDefaultValues && $this->filter === null) {
25
            $this->filter = $this->enum;
26
        }
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function getDataCellValue($model, $key, $index)
33
    {
34
        $value = parent::getDataCellValue($model, $key, $index);
35
        return ArrayHelper::getValue($this->enum, $value, $value);
36
    }
37
}
38