DoctrineObjectConstructor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 32
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A construct() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Darkilliant\ImportBundle\Serializer\JMS;
6
7
use Darkilliant\ImportBundle\Resolver\EntityResolver;
8
use JMS\Serializer\VisitorInterface;
9
use JMS\Serializer\Metadata\ClassMetadata;
10
use JMS\Serializer\DeserializationContext;
11
use JMS\Serializer\Construction\ObjectConstructorInterface;
12
13
/**
14
 * @internal
15
 * Doctrine object constructor for new (or existing) objects during deserialization
16
 */
17
class DoctrineObjectConstructor implements ObjectConstructorInterface
18
{
19
    /** @var array */
20
    protected $config;
21
    private $fallbackConstructor;
22
23
    /** @var EntityResolver */
24
    private $resolver;
25
26 4
    public function __construct(ObjectConstructorInterface $fallbackConstructor, EntityResolver $resolver, array $config)
27
    {
28 4
        $this->fallbackConstructor = $fallbackConstructor;
29 4
        $this->config = $config;
30 4
        $this->resolver = $resolver;
31 4
    }
32
33
    /**
34
     * {@inheritdoc}
35
     *
36
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
37
     */
38 4
    public function construct(VisitorInterface $visitor, ClassMetadata $metadata, $data, array $type, DeserializationContext $context)
39
    {
40 4
        if (!isset($this->config[$metadata->name])) {
41 1
            return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
42
        }
43
44
        // Deprecated ignored for compatibilty with lower version of jms serializer
45 3
        $class = $metadata->name;
46 3
        $entity = $this->resolver->resolve($class, $data, /* @scrutinizer ignore-deprecated */ $context->attributes->all()['entity_resolver'][$class] ?? null);
47
48 3
        return (null === $entity) ? new $class() : $entity;
49
    }
50
}
51