Mapping::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 3
crap 6
1
<?php
2
3
namespace Sco\Admin\Display\Columns;
4
5
class Mapping extends Column
6
{
7
    protected $type = 'mapping';
8
9
    protected $mappings = [
10
        '0' => 'No',
11
        '1' => 'Yes',
12
    ];
13
14
    public function __construct($name, $label, $mappings = null)
15
    {
16
        parent::__construct($name, $label);
17
18
        if ($mappings) {
19
            $this->setMappings($mappings);
20
        }
21
    }
22
23
    /**
24
     * @return array
25
     */
26
    public function getMappings()
27
    {
28
        return $this->mappings;
29
    }
30
31
    /**
32
     * @param array|\Closure $mappings
33
     *
34
     * @return $this
35
     */
36
    public function setMappings($mappings)
37
    {
38
        if ($mappings instanceof \Closure) {
39
            $mappings = $mappings();
40
        }
41
42
        $this->mappings = (array) $mappings;
43
44
        return $this;
45
    }
46
47
    public function getValue()
48
    {
49
        $value = parent::getValue();
50
51
        return $this->mappings[$value] ?? $value;
52
    }
53
}
54