Completed
Push — develop ( 6f0e36...909bf7 )
by Javier
10:20
created

CarbonToArrayTransformer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A reverseTransform() 0 9 2
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\CarbonBundle\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
32 1
        if ($dateTime) {
33 1
            $dateTime = Carbon::instance($dateTime);
34
        }
35
36 1
        return $dateTime;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $dateTime could return the type DateTime which includes types incompatible with the type-hinted return null|Carbon\Carbon. Consider adding an additional type-check to rule them out.
Loading history...
37
    }
38
}
39