Passed
Branch develop (e08659)
by Nicolas
04:47
created

DateTimeNormalizer::supportsNormalization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Serializer\Normalizer;
6
7
use Carbon\Carbon;
8
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
9
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
10
11
/**
12
 * DateTimeNormalizer.
13
 */
14
class DateTimeNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 14
    public function normalize($object, $format = null, array $context = []): string
20
    {
21 14
        return Carbon::instance($object)->toISOString();
0 ignored issues
show
Bug Best Practice introduced by
The expression return Carbon\Carbon::in...$object)->toISOString() could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 28
    public function supportsNormalization($data, $format = null): bool
28
    {
29 28
        return $data instanceof \DateTime;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 28
    public function hasCacheableSupportsMethod(): bool
36
    {
37 28
        return true;
38
    }
39
}
40