CarbonToDateTimeTransformer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A reverseTransform() 0 3 2
A transform() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Xgc\CarbonBundle\Form\DataTransformer;
5
6
use Carbon\Carbon;
7
use DateTime;
8
use Symfony\Component\Form\DataTransformerInterface;
9
10
/**
11
 * Class CarbonToDateTimeTransformer
12
 * @package Xgc\XgcCarbonBundle\Form\DataTransformer
13
 */
14
class CarbonToDateTimeTransformer implements DataTransformerInterface
15
{
16
17
    /**
18
     * Carbon actually inherits DateTime, no conversion needed
19
     *
20
     * @param null|Carbon $value
21
     *
22
     * @return null|DateTime
23
     */
24 1
    public function transform($value): ?DateTime
25
    {
26 1
        return $value;
27
    }
28
29
    /**
30
     * @param null|DateTime $value
31
     *
32
     * @return null|Carbon
33
     */
34 1
    public function reverseTransform($value): ?Carbon
35
    {
36 1
        return $value ? Carbon::instance($value) : null;
37
    }
38
}
39