Map   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 13
c 0
b 0
f 0
dl 0
loc 28
rs 10
ccs 12
cts 12
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 10 3
A __construct() 0 5 1
1
<?php
2
3
namespace kalanis\kw_table\core\Table\Columns;
4
5
6
use kalanis\kw_connect\core\Interfaces\IRow;
7
8
9
/**
10
 * Class Map
11
 * @package kalanis\kw_table\core\Table\Columns
12
 * Map content from source into something else defined by map
13
 */
14
class Map extends AColumn
15
{
16
    /** @var array<string|int, float|int|string|bool|null> */
17
    protected array $map;
18
    protected string $emptyValue = '';
19
20
    /**
21
     * @param string|int $sourceName
22
     * @param array<string|int, float|int|string|bool|null> $map
23
     * @param string $emptyValue
24
     */
25 3
    public function __construct($sourceName, array $map, string $emptyValue = '')
26
    {
27 3
        $this->sourceName = $sourceName;
28 3
        $this->map = $map;
29 3
        $this->emptyValue = $emptyValue;
30 3
    }
31
32 3
    public function getValue(IRow $source)
33
    {
34 3
        $value = strval(parent::getValue($source));
35
36 3
        if (isset($this->map[$value])) {
37 1
            return $this->map[$value];
38 2
        } else if (empty($value)) {
39 1
            return $this->emptyValue;
40
        } else {
41 1
            return $value;
42
        }
43
    }
44
}
45