Completed
Pull Request — master (#1)
by steven
06:45 queued 03:35
created

CategoryNormalizer::normalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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