Completed
Push — master ( 532d27...dec13a )
by Adam
05:41
created

DateTime::decorate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Boduch\Grid\Decorators;
4
5
use Carbon\Carbon;
6
use Boduch\Grid\Cell;
7
8
class DateTime extends Decorator
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $format;
14
15
    /**
16
     * @param string $format
17
     */
18
    public function __construct(string $format)
19
    {
20
        $this->format = $format;
21
    }
22
23
    /**
24
     * @param Cell $cell
25
     * @return void
26
     */
27
    public function decorate(Cell $cell)
28
    {
29
        if ($cell->getValue()) {
30
            $cell->setValue($this->formatDateTime($cell->getValue()));
31
        }
32
    }
33
34
    /**
35
     * @param $dateTime
36
     * @return string
37
     */
38
    protected function formatDateTime($dateTime)
39
    {
40
        return Carbon::parse($dateTime)->format($this->format);
41
    }
42
}
43