CommentNormalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsNormalization() 0 3 1
A normalize() 0 10 1
A hasCacheableSupportsMethod() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Serializer\Normalizer;
6
7
use App\Entity\Comment;
8
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
9
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
10
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
11
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
12
13
final class CommentNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
14
{
15
    use NormalizerAwareTrait;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 2
    public function normalize($object, string $format = null, array $context = []): array
21
    {
22
        /* @var Comment $object */
23
24
        return [
25 2
            'id' => $object->getId(),
26 2
            'createdAt' => $this->normalizer->normalize($object->getCreatedAt()),
27 2
            'updatedAt' => $this->normalizer->normalize($object->getCreatedAt()),
28 2
            'body' => $object->getBody(),
29 2
            'author' => $this->normalizer->normalize($object->getAuthor()),
30
        ];
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 34
    public function supportsNormalization($data, string $format = null): bool
37
    {
38 34
        return $data instanceof Comment;
39
    }
40
41 34
    public function hasCacheableSupportsMethod(): bool
42
    {
43 34
        return true;
44
    }
45
}
46