RegistrationNormalizer::supportsDenormalization()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Serializer\Normalizer;
4
5
use App\Entity\Registration;
6
use Ds\Component\Config\Service\ConfigService;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Config\Service\ConfigService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Ds\Component\Acl\Serializer\Normalizer\Property\AbstractNormalizer;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Acl\Seriali...erty\AbstractNormalizer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Serial...r\DenormalizerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Serial...zer\NormalizerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Symfony\Component\Serializer\SerializerAwareInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Serial...erializerAwareInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Symfony\Component\Serializer\SerializerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Serializer\SerializerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
/**
14
 * Class RegistrationNormalizer
15
 */
16
final class RegistrationNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
17
{
18
    /**
19
     * @var \Ds\Component\Acl\Serializer\Normalizer\Property\AbstractNormalizer
20
     */
21
    private $decorated;
22
23
    /**
24
     * @var \Symfony\Component\Serializer\SerializerInterface
25
     */
26
    private $serializer;
27
28
    /**
29
     * @var \Ds\Component\Config\Service\ConfigService
30
     */
31
    private $configService;
32
33
    /**
34
     * Constructor
35
     *
36
     * @param \Ds\Component\Acl\Serializer\Normalizer\Property\AbstractNormalizer $decorated
37
     * @param \Ds\Component\Config\Service\ConfigService $configService
38
     */
39
    public function __construct(AbstractNormalizer $decorated, ConfigService $configService)
40
    {
41
        $this->decorated = $decorated;
42
        $this->configService = $configService;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function denormalize($data, $class, $format = null, array $context = [])
49
    {
50
        if (Registration::class === $class) {
51
52
            if (!array_key_exists('owner', $data) || null === $data['owner']) {
53
                $key = 'app.registration.'.strtolower($data['identity']);
54
                $data['owner'] = $this->configService->get($key.'.owner.type');
55
                $data['ownerUuid'] = $this->configService->get($key.'.owner.uuid');
56
            }
57
        }
58
59
        return $this->decorated->denormalize($data, $class, $format, $context);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function normalize($object, $format = null, array $context = [])
66
    {
67
        $data = $this->decorated->normalize($object, $format, $context);
68
69
        return $data;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function supportsDenormalization($data, $type, $format = null)
76
    {
77
        return $this->decorated->supportsDenormalization($data, $type, $format);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function supportsNormalization($data, $format = null)
84
    {
85
        return $this->decorated->supportsNormalization($data, $format);
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function setSerializer(SerializerInterface $serializer)
92
    {
93
        $this->serializer = $serializer;
94
95
        if ($this->decorated instanceof SerializerAwareInterface) {
96
            $this->decorated->setSerializer($serializer);
97
        }
98
    }
99
}
100