Completed
Push — master ( e66c58...0a0a0f )
by Daniel
9s
created

DateTimeColumn::getParent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid\Column;
6
7
use Psi\Component\Grid\ColumnInterface;
8
use Psi\Component\Grid\View\Cell;
9
use Symfony\Component\OptionsResolver\OptionsResolver;
10
11
class DateTimeColumn implements ColumnInterface
12
{
13
    public function buildCell(Cell $cell, array $options)
14
    {
15
        $value = $cell->value;
16
17
        if (null === $value) {
18
            return;
19
        }
20
21
        if (false === $value instanceof \DateTime) {
22
            throw new \InvalidArgumentException(sprintf(
23
                'The DateTime column requires a \DateTime value at "%s", but got "%s"',
24
                $options['property'], is_object($value) ? get_class($value) : gettype($value)
25
            ));
26
        }
27
28
        $cell->template = 'DateTime';
29
        $cell->parameters['format'] = $options['format'];
30
    }
31
32
    public function configureOptions(OptionsResolver $resolver)
33
    {
34
        $resolver->setDefault('format', 'c');
35
    }
36
37
    public function getParent()
38
    {
39
        return PropertyColumn::class;
40
    }
41
}
42