CarbonToArrayTransformer::reverseTransform()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Xgc\CarbonBundle\Form\DataTransformer;
5
6
use Carbon\Carbon;
7
use Symfony\Component\Form\Exception\TransformationFailedException;
8
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
9
10
/**
11
 * Class CarbonToArrayTransformer
12
 *
13
 * @package Xgc\XgcCarbonBundle\Form\DataTransformer
14
 */
15
class CarbonToArrayTransformer extends DateTimeToArrayTransformer
16
{
17
    /**
18
     * Transforms a localized date into a normalized date.
19
     *
20
     * @param array $value Localized date
21
     *
22
     * @return null|Carbon Normalized date
23
     * @throws TransformationFailedException
24
     *
25
     * @throws TransformationFailedException If the given value is not an array,
26
     *                                       if the value could not be transformed
27
     */
28 1
    public function reverseTransform($value): ?Carbon
29
    {
30 1
        $dateTime = parent::reverseTransform($value);
31 1
        $carbon = null;
32
33 1
        if ($dateTime) {
34 1
            $carbon = Carbon::instance($dateTime);
35
        }
36
37 1
        return $carbon;
38
    }
39
}
40