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

IndexConfigurationRepository::getMappings()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 3

Importance

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