Completed
Branch develop (7f369c)
by Nicolas
04:28
created

CommentNormalizer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

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