StrategyDtoDenormalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A denormalize() 0 10 2
A supportsDenormalization() 0 3 1
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\StrategyDto;
21
22
/**
23
 * Converts an array of scalars to valid roadmap StrategyDto instance
24
 */
25
class StrategyDtoDenormalizer implements DenormalizerInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function denormalize($data, $class, $format = null, array $context = [])
31
    {
32
        if (!array_key_exists(StrategyDto::PROPERTY_NAME, $data)) {
33
            throw new UnexpectedValueException('Value for roadmap strategy name property is not exists for hydration.');
34
        }
35
36
        $strategyDto = new StrategyDto();
37
        $strategyDto->setName($data[StrategyDto::PROPERTY_NAME]);
38
39
        return $strategyDto;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function supportsDenormalization($data, $type, $format = null)
46
    {
47
        return StrategyDto::class === $type;
48
    }
49
}
50