IndexConfigurationRepository::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
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