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

CarbonToArrayTransformer::reverseTransform()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 9.6666
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\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