Completed
Push — 6.0-dev ( 1ef812...ceea66 )
by Simonas
01:30
created

ObjectNormalizer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A setAttributeValue() 0 16 4
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[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
12
namespace ONGR\ElasticsearchBundle\Mapping;
13
14
use Doctrine\Common\Cache\Cache;
15
use ONGR\ElasticsearchBundle\Result\ObjectIterator;
16
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
17
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
18
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer as SymfonyObjectNormalizer;
19
20
class ObjectNormalizer extends SymfonyObjectNormalizer
21
{
22
    private $cache;
23
    private $converter;
24
25
    public function __construct(
26
        Cache $cache,
27
        Converter $converter,
28
        NameConverterInterface $nameConverter = null,
29
        PropertyAccessorInterface $propertyAccessor = null
30
    ) {
31
        parent::__construct(null, $nameConverter, $propertyAccessor, null, null, null, []);
32
33
        $this->cache = $cache;
34
        $this->converter = $converter;
35
    }
36
37
    protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = [])
38
    {
39
        $embeddedFields = $this->cache->fetch(DocumentParser::EMBEDDED_CACHED_FIELDS);
40
41
        $class = $embeddedFields[get_class($object)][$attribute] ?? null;
42
43
        try {
44
            if ($class && is_array($value)) {
45
                $value = new ObjectIterator($class, $value, $this->converter, $this->serializer);
0 ignored issues
show
Compatibility introduced by
$this->serializer of type object<Symfony\Component...er\SerializerInterface> is not a sub-type of object<Symfony\Component\Serializer\Serializer>. It seems like you assume a concrete implementation of the interface Symfony\Component\Serializer\SerializerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
46
            }
47
48
            $this->propertyAccessor->setValue($object, $attribute, $value);
49
        } catch (NoSuchPropertyException $exception) {
0 ignored issues
show
Bug introduced by
The class ONGR\ElasticsearchBundle...NoSuchPropertyException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
50
            // Properties not found are ignored
51
        }
52
    }
53
}
54