AbstractTimestampDataTransformer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A reverseTransform() 0 9 2
A transform() 0 9 2
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2021 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\CoreBundle\Form\DataTransformer;
13
14
use DateTime;
15
16
/**
17
 * Abstract timestamp data transformer.
18
 *
19
 * @author webeweb <https://github.com/webeweb>
20
 * @package WBW\Bundle\CoreBundle\Form\DataTransformer
21
 * @abstract
22
 */
23
abstract class AbstractTimestampDataTransformer extends AbstractDateTimeDataTransformer {
24
25
    /**
26
     * {@inheritDoc}
27
     */
28
    public function reverseTransform($value) {
29
30
        /** @var DateTime|null $date */
31
        $date = parent::reverseTransform($value);
32
        if (null === $date) {
33
            return null;
34
        }
35
36
        return $date->getTimestamp();
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function transform($value) {
43
44
        if (null === $value) {
45
            return null;
46
        }
47
48
        $date = new DateTime("@$value");
49
50
        return parent::transform($date);
51
    }
52
}
53