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

DateTimeColumn   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildCell() 0 18 4
A configureOptions() 0 4 1
A getParent() 0 4 1
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