BooleanColumn::getCellContent()   A
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 9
nc 10
nop 1
dl 0
loc 13
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
4
namespace Pfilsx\DataGrid\Grid\Columns;
5
6
7
class BooleanColumn extends DataColumn
8
{
9
    protected $trueValue = 'Yes';
10
    protected $falseValue = 'No';
11
12
    public function getCellContent($entity)
13
    {
14
        if (is_callable($this->value)) {
15
            $result = call_user_func_array($this->value, [$entity]);
16
        } elseif ($this->value !== null) {
17
            $result = $this->value ? $this->trueValue : $this->falseValue;
18
        } else {
19
20
            $result = $entity->{$this->attribute}
21
                ? $this->trueValue
22
                : $this->falseValue;
23
        }
24
        return $this->format == 'html' ? $result : htmlspecialchars($result);
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function getTrueValue(): string
31
    {
32
        return $this->trueValue;
33
    }
34
35
    /**
36
     * @param string $trueValue
37
     */
38
    protected function setTrueValue(string $trueValue): void
39
    {
40
        $this->trueValue = $trueValue;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getFalseValue(): string
47
    {
48
        return $this->falseValue;
49
    }
50
51
    /**
52
     * @param string $falseValue
53
     */
54
    protected function setFalseValue(string $falseValue): void
55
    {
56
        $this->falseValue = $falseValue;
57
    }
58
}
59