RelationColumn   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 17
c 3
b 1
f 0
dl 0
loc 49
rs 10
wmc 13

5 Methods

Rating   Name   Duplication   Size   Complexity  
A checkConfiguration() 0 5 3
A getLabel() 0 5 3
A getLabelAttribute() 0 3 1
A setLabelAttribute() 0 3 1
A getCellContent() 0 10 5
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 $this->label === false
0 ignored issues
show
introduced by
The condition $this->label === false is always false.
Loading history...
26
            ? ''
27
            : (!empty($this->label) ? $this->label : "{$this->attribute}.{$this->labelAttribute}");
28
    }
29
30
31
    public function getCellContent($entity)
32
    {
33
        $obj = $this->getCellValue($entity);
34
        if (is_object($obj)) {
35
            $result = $obj->{'get' . ucfirst($this->labelAttribute)}();
36
            return $this->format === 'html'
37
                ? $result
38
                : htmlspecialchars($result);
39
        }
40
        return is_string($obj) ? (empty($obj) ? $this->emptyValue : $obj) : $this->emptyValue;
41
    }
42
43
    /**
44
     * @return mixed
45
     */
46
    public function getLabelAttribute()
47
    {
48
        return $this->labelAttribute;
49
    }
50
51
    /**
52
     * @param string $labelAttribute
53
     */
54
    protected function setLabelAttribute(string $labelAttribute): void
55
    {
56
        $this->labelAttribute = $labelAttribute;
57
    }
58
}
59