Date   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getValue() 0 10 3
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 Date
11
 * @package kalanis\kw_table\core\Table\Columns
12
 * Date formatted by preset value
13
 */
14
class Date extends AColumn
15
{
16
    protected string $format = '';
17
    protected bool $timestamp = true;
18
19 5
    public function __construct(string $sourceName, string $format = 'Y-m-d', bool $timestamp = true)
20
    {
21 5
        $this->sourceName = $sourceName;
22 5
        $this->format = $format;
23 5
        $this->timestamp = $timestamp;
24 5
    }
25
26 3
    public function getValue(IRow $source)
27
    {
28 3
        $value = parent::getValue($source);
29 3
        if (empty($value)) {
30 1
            return 0;
31
        }
32 2
        if (!$this->timestamp) {
33 1
            $value = strtotime(strval($value));
34
        }
35 2
        return date($this->format, intval($value));
36
    }
37
}
38