Completed
Pull Request — dev (#40)
by
unknown
04:54
created

RequestNormalizer::normalize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 2.003

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 10
cts 11
cp 0.9091
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 3
crap 2.003
1
<?php
2
3
namespace AppBundle\Serializer;
4
5
use AppBundle\Entity\FormRequest;
6
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
7
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
8
use Symfony\Component\Serializer\Exception\LogicException;
9
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
10
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
11
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
12
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
13
14 View Code Duplication
class RequestNormalizer extends ObjectNormalizer
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /**
17
     * RequestNormalizer constructor.
18
     *
19
     * @param ClassMetadataFactoryInterface|null $classMDF
20
     * @param NameConverterInterface|null $nameCv
21
     * @param PropertyAccessorInterface|null $propAs
22
     * @param PropertyTypeExtractorInterface|null $propTE
23
     */
24 4
    public function __construct($classMDF, $nameCv, $propAs, $propTE)
25
    {
26 4
        parent::__construct($classMDF, $nameCv, $propAs, $propTE);
27 4
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 4
    public function supportsNormalization($data, $format = null)
33
    {
34 4
        return $data instanceof FormRequest;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function normalize($object, $format = null, array $context = [])
41
    {
42 1
        if (!$this->serializer instanceof NormalizerInterface) {
43
            throw new LogicException('Cannot normalize attributes because injected serializer is not a normalizer');
44
        }
45
        /** @var FormRequest $request */
46 1
        $request = &$object;
47
48 1
        return $this->serializer->normalize(new \ArrayObject([
49 1
            'id' => $request->getId(),
50 1
            'type' => $request->getType()->getId(),
51 1
            'status' => $request->getStatus(),
52 1
            'date' => $request->getDate(),
53 1
            'create' => $request->getCreatedAt(),
54 1
            'update' => $request->getUpdatedAt(),
55
        ]), $format, $context);
56
    }
57
}
58