Passed
Pull Request — master (#4)
by steven
02:46
created

CategoryNormalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsNormalization() 0 3 2
A normalize() 0 6 1
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Question\Serializers;
4
5
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
6
use VSV\GVQ_API\Question\Models\Category;
7
8
class CategoryNormalizer implements NormalizerInterface
9
{
10
    /**
11
     * @inheritdoc
12
     */
13
    public function normalize($category, $format = null, array $context = []): array
14
    {
15
        /** @var Category $category */
16
        return [
17
            'id' => $category->getId()->toString(),
18
            'name' => $category->getName()->toNative(),
19
        ];
20
    }
21
22
    /**
23
     * @inheritdoc
24
     */
25
    public function supportsNormalization($data, $format = null): bool
26
    {
27
        return ($data instanceof Category) && ($format === 'json');
28
    }
29
}
30