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

AttributeColumn   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A renderValue() 0 17 4
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
}