Passed
Push — master ( 2a5d2e...e3462d )
by Andy
02:12
created

DateTimeNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 42
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setFormat() 0 6 1
A getFormat() 0 4 1
A getNormalizedValue() 0 4 1
1
<?php
2
3
namespace Palmtree\Csv\Normalizer;
4
5
class DateTimeNormalizer extends AbstractNormalizer
6
{
7
    protected $format;
8
9
    /**
10
     * DateTimeNormalizer constructor.
11
     *
12
     * @param null|NormalizerInterface $normalizer
13
     * @param string                   $format
14
     */
15
    public function __construct($normalizer = null, $format = 'Y-m-d')
16
    {
17
        parent::__construct($normalizer);
18
19
        $this->setFormat($format);
20
    }
21
22
    /**
23
     * @param string $format
24
     *
25
     * @return self
26
     */
27
    public function setFormat($format)
28
    {
29
        $this->format = $format;
30
31
        return $this;
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function getFormat()
38
    {
39
        return $this->format;
40
    }
41
42
    protected function getNormalizedValue($value)
43
    {
44
        return \DateTime::createFromFormat($this->getFormat(), $value);
45
    }
46
}
47