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

CommentNormalizer::supportsNormalization()   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 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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