Completed
Push — master ( 103460...224772 )
by GBProd
02:10
created

IndexConfigurationRepository   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 86
Duplicated Lines 23.26 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 0
dl 20
loc 86
ccs 22
cts 22
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 8 2
A getSettings() 10 10 3
A getMappings() 10 10 3
A getMapping() 0 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
namespace GBProd\ElasticaExtraBundle\Repository;
4
5
/**
6
 * Repository for index configuration
7
 *
8
 * @author gbprod <[email protected]>
9
 */
10
class IndexConfigurationRepository
11
{
12
    /**
13
     * @var array
14
     */
15
    private $config;
16
17
    /**
18
     * @param array $config
19
     */
20 16
    public function __construct(array $config = array())
21
    {
22 16
        $this->config = $config;
23 16
    }
24
25
    /**
26
     * Get all configuration for an index
27
     *
28
     * @param string $index
29
     *
30
     * @return array|null
31
     */
32 11
    public function get($index)
33
    {
34 11
        if (!isset($this->config[$index])) {
35 4
            return null;
36
        }
37
38 7
        return $this->config[$index];
39
    }
40
41
    /**
42
     * Get settings for an index
43
     *
44
     * @param string $index
45
     *
46
     * @return array|null
47
     */
48 3 View Code Duplication
    public function getSettings($index)
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...
49
    {
50 3
        $config = $this->get($index);
51
        
52 3
        if (null !== $config && isset($config['settings'])) {
53 2
            return $config['settings'];
54
        }
55
56 1
        return null;
57
    }
58
    
59
    /**
60
     * Get mappings for an index
61
     *
62
     * @param string $index
63
     *
64
     * @return array|null
65
     */
66 4 View Code Duplication
    public function getMappings($index)
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...
67
    {
68 4
        $config = $this->get($index);
69
        
70 4
        if (null === $config || !isset($config['mappings'])) {
71 1
            return null;
72
        }
73
        
74 3
        return $config['mappings'];
75
    }
76
    
77
    /**
78
     * Get mapping for a type
79
     *
80
     * @param string $index
81
     * @param string $type
82
     *
83
     * @return array|null
84
     */
85 3
    public function getMapping($index, $type)
86
    {
87 3
        $mappings = $this->getMappings($index);
88
        
89 3
        if (!isset($mappings[$type])) {
90 1
            return null;
91
        }
92
        
93 2
        return $mappings[$type];
94
    }
95
}
96