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

NameConverter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 64.52 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A normalize() 10 10 2
A denormalize() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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