DateColumn   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 30
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDateFormat() 0 3 1
A getDateFormat() 0 3 1
A getCellContent() 0 10 5
1
<?php
2
3
4
namespace Pfilsx\DataGrid\Grid\Columns;
5
6
7
use DateTime;
8
9
class DateColumn extends DataColumn
10
{
11
    protected $dateFormat = 'd.m.Y';
12
13
    public function getCellContent($entity)
14
    {
15
        $value = $this->getCellValue($entity);
16
        if ($value instanceof DateTime) {
17
            return $value->format($this->dateFormat);
18
        } elseif (is_string($value) && !empty($this->dateFormat)) {
19
            return date($this->dateFormat, strtotime($value));
20
        }
21
        $value = (string)$value;
22
        return empty($value) ? $this->emptyValue : $value;
23
    }
24
25
    /**
26
     * @return string
27
     */
28
    public function getDateFormat(): ?string
29
    {
30
        return $this->dateFormat;
31
    }
32
33
    /**
34
     * @param string $dateFormat
35
     */
36
    protected function setDateFormat(?string $dateFormat): void
37
    {
38
        $this->dateFormat = $dateFormat;
39
    }
40
}
41