DateTimeNormalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasCacheableSupportsMethod() 0 3 1
A normalize() 0 3 1
A supportsNormalization() 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
final class DateTimeNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16 14
    public function normalize($object, string $format = null, array $context = []): ?string
17
    {
18 14
        return Carbon::instance($object)->toISOString();
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 34
    public function supportsNormalization($data, string $format = null): bool
25
    {
26 34
        return $data instanceof \DateTime;
27
    }
28
29 34
    public function hasCacheableSupportsMethod(): bool
30
    {
31 34
        return true;
32
    }
33
}
34