Completed
Push — master ( 9d2442...b1f272 )
by Denis
01:49
created

AttributeColumn::renderValue()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
namespace Woo\GridView\Columns;
4
5
use Woo\GridView\Exceptions\ColumnRenderException;
6
7
class AttributeColumn extends BaseColumn
8
{
9
    public function __construct($config)
10
    {
11
        if (is_string($config)) {
12
            $this->title = ucfirst(str_replace('_', ' ', $config));
13
            $this->value = $config;
14
        }
15
16
        parent::__construct([]);
17
    }
18
19
    /**
20
     * @inheritdoc
21
     * @throws ColumnRenderException
22
     */
23
    public function renderValue($row)
24
    {
25
        if (is_array($row)) {
26
27
            if (!isset($row[$this->value])) {
28
                return null;
29
            }
30
31
            return $row[$this->value];
32
        }
33
34
        if (!isset($row->{$this->value})) {
35
            return null;
36
        }
37
38
        return $row->{$this->value};
39
    }
40
}