ConfigurationDtoDenormalizer::denormalize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 2
nc 2
nop 4
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\AnthillBundle\Vacancy\Normalizer\Roadmap;
17
18
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
19
use UnexpectedValueException;
20
use Veslo\AnthillBundle\Dto\Vacancy\Roadmap\ConfigurationDto;
21
22
/**
23
 * Converts an array of scalars to valid roadmap ConfigurationDto instance
24
 */
25
class ConfigurationDtoDenormalizer implements DenormalizerInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function denormalize($data, $class, $format = null, array $context = [])
31
    {
32
        if (!array_key_exists(ConfigurationDto::PROPERTY_KEY, $data)) {
33
            throw new UnexpectedValueException(
34
                'Value for roadmap configuration key property is not exists for hydration.'
35
            );
36
        }
37
38
        $configurationDto = new ConfigurationDto();
39
        $configurationDto->setKey($data[ConfigurationDto::PROPERTY_KEY]);
40
41
        return $configurationDto;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function supportsDenormalization($data, $type, $format = null)
48
    {
49
        return ConfigurationDto::class === $type;
50
    }
51
}
52