Boolean   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

13 Methods

Rating   Name   Duplication   Size   Complexity  
A getTrueLabel() 0 4 1
A setTrueLabel() 0 4 1
A getFalseLabel() 0 4 1
A setFalseLabel() 0 4 1
A getFalseIcon() 0 4 1
A setFalseIcon() 0 4 1
A getTrueIcon() 0 4 1
A setTrueIcon() 0 4 1
A setTextual() 0 4 1
A isTextual() 0 4 1
A decorate() 0 8 2
A renderGraphical() 0 10 1
A renderTextual() 0 4 1
1
<?php
2
3
namespace Boduch\Grid\Decorators;
4
5
use Boduch\Grid\Cell;
6
7
class Boolean extends Decorator
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $trueLabel = 'Yes';
13
14
    /**
15
     * @var string
16
     */
17
    protected $falseLabel = 'No';
18
19
    /**
20
     * @var string
21
     */
22
    protected $trueIcon = 'fa-check-circle';
23
24
    /**
25
     * @var string
26
     */
27
    protected $falseIcon = 'fa-minus';
28
29
    /**
30
     * @var bool
31
     */
32
    protected $textual = false;
33
34
    /**
35
     * @return string
36
     */
37
    public function getTrueLabel()
38
    {
39
        return $this->trueLabel;
40
    }
41
42
    /**
43
     * @param string $trueLabel
44
     */
45
    public function setTrueLabel($trueLabel)
46
    {
47
        $this->trueLabel = $trueLabel;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getFalseLabel()
54
    {
55
        return $this->falseLabel;
56
    }
57
58
    /**
59
     * @param string $falseLabel
60
     */
61
    public function setFalseLabel($falseLabel)
62
    {
63
        $this->falseLabel = $falseLabel;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getFalseIcon()
70
    {
71
        return $this->falseIcon;
72
    }
73
74
    /**
75
     * @param string $falseIcon
76
     */
77
    public function setFalseIcon($falseIcon)
78
    {
79
        $this->falseIcon = $falseIcon;
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getTrueIcon()
86
    {
87
        return $this->trueIcon;
88
    }
89
90
    /**
91
     * @param string $trueIcon
92
     */
93
    public function setTrueIcon($trueIcon)
94
    {
95
        $this->trueIcon = $trueIcon;
96
    }
97
98
    /**
99
     * @param $flag
100
     */
101
    public function setTextual($flag)
102
    {
103
        $this->textual = (bool) $flag;
104
    }
105
106
    /**
107
     * @return bool
108
     */
109
    public function isTextual()
110
    {
111
        return $this->textual;
112
    }
113
114
    /**
115
     * @param Cell $cell
116
     * @return void
117
     */
118
    public function decorate(Cell $cell)
119
    {
120
        if ($this->textual) {
121
            $this->renderTextual($cell);
122
        } else {
123
            $this->renderGraphical($cell);
124
        }
125
    }
126
127
    /**
128
     * @param Cell $cell
129
     */
130
    protected function renderGraphical(Cell $cell)
131
    {
132
        $class = [0 => $this->falseIcon, 1 => $this->trueIcon][$cell->getUnescapedValue()];
133
        // disable auto escape so we can display <a> html tag in cell
134
        $cell->getColumn()->setAutoescape(false);
135
136
        $cell->setValue(
137
            $cell->getColumn()->getGrid()->getGridHelper()->getHtmlBuilder()->tag('i', '', ['class' => "fa $class"])
138
        );
139
    }
140
141
    /**
142
     * @param Cell $cell
143
     */
144
    protected function renderTextual(Cell $cell)
145
    {
146
        $cell->setValue([0 => $this->falseLabel, 1 => $this->trueLabel][$cell->getUnescapedValue()]);
147
    }
148
}
149