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

NameConverter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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