Mapping   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 49
ccs 0
cts 24
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getMappings() 0 4 1
A setMappings() 0 10 2
A getValue() 0 6 1
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