Completed
Push — master ( 4d8439...98d3f4 )
by Derek Stephen
05:28 queued 11s
created

DateTimeTransformer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Del\Form\Field\Transformer;
4
5
use DateTime;
6
use Del\Form\Field\TransformerInterface;
7
8
class DateTimeTransformer implements TransformerInterface
9
{
10
    /** @var string $dateFormat */
11
    private $dateFormat;
12
13
    /**
14
     * DateTimeTransformer constructor.
15
     * @param string $dateFormat
16
     */
17
    public function __construct(string $dateFormat)
18
    {
19
        $this->dateFormat = $dateFormat;
20
    }
21
22
    /**
23
     * @param mixed $value
24
     * @return string
25
     */
26
    public function input($value): string
27
    {
28
        if ($value instanceof DateTime) {
29
            return $value->format($this->dateFormat);
30
        }
31
32
        return $value;
33
    }
34
35
    /**
36
     * @return DateTime
37
     */
38
    public function output(string $value)
39
    {
40
        return DateTime::createFromFormat($this->dateFormat, $value);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression \DateTime::createFromFor...s->dateFormat, $value); of type DateTime|false adds false to the return on line 40 which is incompatible with the return type documented by Del\Form\Field\Transform...TimeTransformer::output of type DateTime. It seems like you forgot to handle an error condition.
Loading history...
41
    }
42
}