Passed
Branch feature/php7 (3e8a2f)
by Andy
04:54
created

DateTimeNormalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
dl 0
loc 20
ccs 0
cts 12
cp 0
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getNormalizedValue() 0 3 1
A getFormat() 0 3 1
A setFormat() 0 5 1
1
<?php
2
3
namespace Palmtree\Csv\Normalizer;
4
5
class DateTimeNormalizer extends AbstractNormalizer
6
{
7
    /** @var string */
8
    private $format = 'Y-m-d';
9
10
    public function setFormat(string $format): self
11
    {
12
        $this->format = $format;
13
14
        return $this;
15
    }
16
17
    public function getFormat(): string
18
    {
19
        return $this->format;
20
    }
21
22
    protected function getNormalizedValue(string $value): \DateTime
23
    {
24
        return \DateTime::createFromFormat($this->getFormat(), $value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return DateTime::createF...s->getFormat(), $value) could return the type false which is incompatible with the type-hinted return DateTime. Consider adding an additional type-check to rule them out.
Loading history...
25
    }
26
}
27