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

CommentNormalizer::hasCacheableSupportsMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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