Completed
Push — master ( 650783...0c9838 )
by wen
15:06
created

Mapping   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

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 $mappings = [
8
        '0' => 'No',
9
        '1' => 'Yes',
10
    ];
11
12
    public function __construct($name, $label, $mappings = null)
13
    {
14
        parent::__construct($name, $label);
15
16
        if ($mappings) {
17
            $this->setMappings($mappings);
18
        }
19
    }
20
21
    /**
22
     * @return array
23
     */
24
    public function getMappings()
25
    {
26
        return $this->mappings;
27
    }
28
29
    /**
30
     * @param array|\Closure $mappings
31
     *
32
     * @return $this
33
     */
34
    public function setMappings($mappings)
35
    {
36
        if ($mappings instanceof \Closure) {
37
            $mappings = $mappings();
38
        }
39
40
        $this->mappings = (array) $mappings;
41
42
        return $this;
43
    }
44
45
    public function getValue()
46
    {
47
        $value = parent::getValue();
48
49
        return $this->mappings[$value] ?? $value;
50
    }
51
}
52