Completed
Pull Request — dev (#9)
by Arnaud
02:46
created

Date   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 87.5%

Importance

Changes 2
Bugs 2 Features 0
Metric Value
wmc 5
c 2
b 2
f 0
lcom 2
cbo 3
dl 0
loc 53
ccs 14
cts 16
cp 0.875
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 8 2
A configureOptions() 0 8 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 1
    public function render($value)
29
    {
30 1
        if ($value instanceof DateTime) {
31 1
            $value = $value->format($this->format);
32 1
        }
33
34 1
        return $value;
35
    }
36
37
    /**
38
     * @param OptionsResolver $resolver
39
     */
40 1
    public function configureOptions(OptionsResolver $resolver)
41
    {
42 1
        $resolver->setDefaults([
43 1
            'format' => $this
44
                ->applicationConfiguration
45 1
                ->getParameter('date_format'),
46 1
        ]);
47 1
    }
48
49
    /**
50
     * @param array $options
51
     */
52 1
    public function setOptions(array $options)
53
    {
54 1
        $this->format = $options['format'];
55 1
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getType()
61
    {
62
        return 'date';
63
    }
64
}
65