PreviewNormalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsNormalization() 0 3 1
A normalize() 0 17 2
1
<?php
2
3
/*
4
 * This file is part of the Veslo project <https://github.com/symfony-doge/veslo>.
5
 *
6
 * (C) 2019 Pavel Petrov <[email protected]>.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://opensource.org/licenses/GPL-3.0 GPL-3.0
12
 */
13
14
declare(strict_types=1);
15
16
namespace Veslo\SanityBundle\Vacancy\Index\Normalizer;
17
18
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
19
use Veslo\SanityBundle\Entity\Vacancy\Index;
20
21
/**
22
 * Converts sanity index entity into a set of arrays/scalars for preview actions (e.g. logging)
23
 */
24
class PreviewNormalizer implements NormalizerInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     *
29
     * @var Index $object A sanity index entity
30
     */
31
    public function normalize($object, $format = null, array $context = [])
32
    {
33
        $indexValueNormalized = $object->getValue();
34
35
        $tags           = $object->getTags();
36
        $tagsNormalized = [];
37
38
        foreach ($tags as $tag) {
39
            $tagName        = $tag->getName();
40
            $tagDescription = $tag->getDescription();
41
42
            $tagsNormalized[] = ['name' => $tagName, 'description' => $tagDescription];
43
        }
44
45
        return [
46
            'value' => $indexValueNormalized,
47
            'tags'  => $tagsNormalized,
48
        ];
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function supportsNormalization($data, $format = null)
55
    {
56
        return $data instanceof Index;
57
    }
58
}
59