Completed
Push — master ( f15fe2...9a8393 )
by Pavel
07:23 queued 11s
created

RelationColumn::getHeadContent()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 7
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A RelationColumn::getLabel() 0 3 2
1
<?php
2
3
4
namespace Pfilsx\DataGrid\Grid\Columns;
5
6
7
8
class RelationColumn extends DataColumn
9
{
10
    protected $labelAttribute;
11
12
    protected function checkConfiguration()
13
    {
14
        parent::checkConfiguration();
15
        if (!is_string($this->labelAttribute) || empty($this->labelAttribute)) {
16
            $this->labelAttribute = 'id';
17
        }
18
    }
19
20
    /**
21
     * @return string
22
     */
23
    public function getLabel(): string
24
    {
25
        return !empty($this->label) ? $this->label : "{$this->attribute}.{$this->labelAttribute}";
26
    }
27
28
29
    public function getCellContent($entity)
30
    {
31
        $obj = $this->getCellValue($entity);
32
        if (is_object($obj)) {
33
            $result = $obj->{'get' . ucfirst($this->labelAttribute)}();
34
            return $this->format === 'html'
35
                ? $result
36
                : htmlspecialchars($result);
37
        }
38
        return is_string($obj) ? $obj : '';
39
    }
40
41
    /**
42
     * @return mixed
43
     */
44
    public function getLabelAttribute()
45
    {
46
        return $this->labelAttribute;
47
    }
48
49
    /**
50
     * @param string $labelAttribute
51
     */
52
    protected function setLabelAttribute(string $labelAttribute): void
53
    {
54
        $this->labelAttribute = $labelAttribute;
55
    }
56
}
57