Completed
Push — 0.3-dev ( 291149...449c2f )
by Arnaud
14:26
created

Date   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 2
cbo 3
dl 0
loc 42
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 8 2
A configureOptions() 0 6 1
A setOptions() 0 4 1
A getType() 0 4 1
1
<?php
2
3
namespace LAG\AdminBundle\Field\Field;
4
5
use LAG\AdminBundle\Field\Field;
6
use DateTime;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
/**
10
 * Date field.
11
 */
12
class Date extends Field
13
{
14
    /**
15
     * Date format.
16
     *
17
     * @var string
18
     */
19
    protected $format;
20
21
    /**
22
     * Render and format a Datetime.
23
     *
24
     * @param $value
25
     *
26
     * @return string
27
     */
28
    public function render($value)
29
    {
30
        if ($value instanceof DateTime) {
31
            $value = $value->format($this->format);
32
        }
33
34
        return $value;
35
    }
36
37
    public function configureOptions(OptionsResolver $resolver)
38
    {
39
        $resolver->setDefaults([
40
            'format' => $this->configuration->getDateFormat(),
41
        ]);
42
    }
43
44
    public function setOptions(array $options)
45
    {
46
        $this->format = $options['format'];
47
    }
48
49
    public function getType()
50
    {
51
        return 'date';
52
    }
53
}
54