Completed
Push — master ( 481507...e81850 )
by Denis
01:52
created

AttributeColumn::_renderValue()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 4
nop 1
dl 0
loc 14
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
namespace Woo\GridView\Columns;
4
5
use Woo\GridView\Exceptions\ColumnRenderException;
6
use Woo\GridView\Exceptions\GridViewConfigException;
7
8
class AttributeColumn extends BaseColumn
9
{
10
    /**
11
     * AttributeColumn constructor.
12
     * @param $config
13
     * @throws GridViewConfigException
14
     */
15
    public function __construct($config)
16
    {
17
        parent::__construct($config);
18
19
        if (empty($this->title)) {
20
            $this->title = ucfirst(str_replace('_', ' ', $this->value));
21
        }
22
    }
23
24
    /**
25
     * @return array
26
     */
27
    protected function configTests(): array
28
    {
29
        return array_merge(parent::configTests(), [
30
            'value' => 'string',
31
        ]);
32
    }
33
34
    /**
35
     * @inheritdoc
36
     * @throws ColumnRenderException
37
     * @throws GridViewConfigException
38
     */
39
    public function _renderValue($row)
40
    {
41
        if (is_array($row)) {
42
43
            if (isset($row[$this->value]) && $row[$this->value] !== null) {
44
                return $row[$this->value];
45
            }
46
47
        } elseif (isset($row->{$this->value}) && $row->{$this->value} !== null) {
48
            return $row->{$this->value};
49
        }
50
51
        return $this->emptyValue;
52
    }
53
}