AcceptanceNormalizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 15 2
A __construct() 0 3 1
A supportsNormalization() 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;
17
18
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
19
use Veslo\AnthillBundle\Dto\Vacancy\Collector\AcceptanceDto;
20
21
/**
22
 * Converts vacancy acceptance context object into a set of arrays/scalars
23
 */
24
class AcceptanceNormalizer implements NormalizerInterface
25
{
26
    /**
27
     * Converts an vacancy scan result object into a set of arrays/scalars
28
     *
29
     * @var ScanResultNormalizer
30
     */
31
    private $normalizer;
32
33
    /**
34
     * AcceptanceNormalizer constructor.
35
     *
36
     * @param ScanResultNormalizer $normalizer Converts an vacancy scan result object into a set of arrays/scalars
37
     */
38
    public function __construct(ScanResultNormalizer $normalizer)
39
    {
40
        $this->normalizer = $normalizer;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     *
46
     * @var AcceptanceDto $object Context of vacancy data that has been accepted for persisting and research
47
     */
48
    public function normalize($object, $format = null, array $context = [])
49
    {
50
        $scanResult           = $object->getData();
51
        $scanResultNormalized = $this->normalizer->normalize($scanResult, $format, $context);
52
53
        $conditions           = $object->getConditions(); // iterable
54
        $conditionsNormalized = [];
55
56
        foreach ($conditions as $condition) {
57
            $conditionsNormalized[] = $condition /** ->getDescription() */;
58
        }
59
60
        $acceptanceNormalized = array_merge(['conditions' => $conditionsNormalized], $scanResultNormalized);
0 ignored issues
show
Bug introduced by
It seems like $scanResultNormalized can also be of type boolean and double and integer and null and string; however, parameter $arrays of array_merge() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
        $acceptanceNormalized = array_merge(['conditions' => $conditionsNormalized], /** @scrutinizer ignore-type */ $scanResultNormalized);
Loading history...
61
62
        return $acceptanceNormalized;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function supportsNormalization($data, $format = null)
69
    {
70
        return $data instanceof AcceptanceDto;
71
    }
72
}
73