DateTimeColumn::buildCell()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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