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

DateTimeNormalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsNormalization() 0 3 1
A hasCacheableSupportsMethod() 0 3 1
A normalize() 0 3 1
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