Date::getValue()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
cc 3
nc 3
nop 1
crap 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