IndexConfigurationRepository   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 94
Duplicated Lines 25.53 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 24
loc 94
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 8 2
A getSettings() 14 14 3
A getMappings() 10 10 3
A getMapping() 0 14 3

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 5
            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) {
53 2
            return null;
54
        }
55
56 2
        if (!isset($config['settings'])) {
57 1
            return [];
58
        }
59
60 2
        return $config['settings'];
61
    }
62
63
    /**
64
     * Get mappings for an index
65
     *
66
     * @param string $index
67
     *
68
     * @return array|null
69
     */
70 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...
71
    {
72 4
        $config = $this->get($index);
73
74 4
        if (null === $config || !isset($config['mappings'])) {
75 1
            return null;
76
        }
77
78 3
        return $config['mappings'];
79
    }
80
81
    /**
82
     * Get mapping for a type
83
     *
84
     * @param string $index
85
     * @param string $type
86
     *
87
     * @return array|null
88
     */
89 3
    public function getMapping($index, $type)
90
    {
91 3
        $mappings = $this->getMappings($index);
92
93 3
        if (!isset($mappings[$type])) {
94 2
            return null;
95
        }
96
97 2
        if (!isset($mappings[$type]['properties'])) {
98 1
            return [];
99
        }
100
101 2
        return $mappings[$type]['properties'];
102
    }
103
}
104