CommentNormalizer::normalize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
c 1
b 0
f 1
nc 1
nop 3
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 1
rs 10
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