Passed
Push — master ( bc13b6...650a1b )
by Nicolas
08:26 queued 04:11
created

CommentNormalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 34
ccs 10
cts 10
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 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
/**
14
 * CommentNormalizer.
15
 */
16
class CommentNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
17
{
18
    use NormalizerAwareTrait;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 2
    public function normalize($object, $format = null, array $context = []): array
24
    {
25
        /* @var Comment $object */
26
27
        return [
28 2
            'id' => $object->getId(),
29 2
            'createdAt' => $this->normalizer->normalize($object->getCreatedAt()),
30 2
            'updatedAt' => $this->normalizer->normalize($object->getCreatedAt()),
31 2
            'body' => $object->getBody(),
32 2
            'author' => $this->normalizer->normalize($object->getAuthor()),
33
        ];
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 28
    public function supportsNormalization($data, $format = null): bool
40
    {
41 28
        return $data instanceof Comment;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 28
    public function hasCacheableSupportsMethod(): bool
48
    {
49 28
        return true;
50
    }
51
}
52