Completed
Pull Request — 6.0-dev (#868)
by Simonas
01:38
created

NameConverter::denormalize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 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 Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
16
17
class NameConverter implements AdvancedNameConverterInterface
18
{
19
    private $cache;
20
21
    public function __construct(Cache $cache)
22
    {
23
        $this->cache = $cache;
24
    }
25
26 View Code Duplication
    public function normalize($propertyName, string $class = null, string $format = null, array $context = [])
0 ignored issues
show
Duplication introduced by
This method 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...
27
    {
28
        $fields = $this->cache->fetch(DocumentParser::OBJ_CACHED_FIELDS);
29
30
        if (isset($fields[$class])) {
31
            return $fields[$class][$propertyName] ?? $propertyName;
32
        }
33
34
        return $propertyName;
35
    }
36
37 View Code Duplication
    public function denormalize($propertyName, string $class = null, string $format = null, array $context = [])
0 ignored issues
show
Duplication introduced by
This method 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...
38
    {
39
        $fields = $this->cache->fetch(DocumentParser::ARRAY_CACHED_FIELDS);
40
41
        if (isset($fields[$class])) {
42
            return $fields[$class][$propertyName] ?? $propertyName;
43
        }
44
45
        return $propertyName;
46
    }
47
}
48