Completed
Pull Request — master (#1193)
by
unknown
41:53
created

IndexConfig   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 111
ccs 18
cts 21
cp 0.8571
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 4
A getElasticSearchName() 0 4 1
A getSettings() 0 4 1
A getType() 0 8 2
A getTypes() 0 4 1
A isUseAlias() 0 4 1
A getName() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of the FOSElasticaBundle project.
5
 *
6
 * (c) Tim Nagel <[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 FOS\ElasticaBundle\Configuration;
13
14
class IndexConfig
15
{
16
    /**
17
     * The name of the index for ElasticSearch.
18
     *
19
     * @var string
20
     */
21
    private $elasticSearchName;
22
23
    /**
24
     * The internal name of the index. May not be the same as the name used in ElasticSearch,
25
     * especially if aliases are enabled.
26
     *
27
     * @var string
28
     */
29
    private $name;
30
31
    /**
32
     * An array of settings sent to ElasticSearch when creating the index.
33
     *
34
     * @var array
35
     */
36
    private $settings;
37
38
    /**
39
     * All types that belong to this index.
40
     *
41
     * @var TypeConfig[]
42
     */
43
    private $types;
44
45
    /**
46
     * Indicates if the index should use an alias, allowing an index repopulation to occur
47
     * without overwriting the current index.
48
     *
49
     * @var bool
50
     */
51
    private $useAlias = false;
52
53
    /**
54
     * Constructor expects an array as generated by the Container Configuration builder.
55
     *
56
     * @param string       $name
57
     * @param TypeConfig[] $types
58
     * @param array        $config
59
     */
60 20
    public function __construct($name, array $types, array $config)
61
    {
62 20
        $this->elasticSearchName = isset($config['elasticSearchName']) ? $config['elasticSearchName'] : $name;
63 20
        $this->name = $name;
64 20
        $this->settings = isset($config['settings']) ? $config['settings'] : array();
65 20
        $this->types = $types;
66 20
        $this->useAlias = isset($config['useAlias']) ? $config['useAlias'] : false;
67 20
    }
68
69
    /**
70
     * @return string
71
     */
72 9
    public function getElasticSearchName()
73
    {
74 9
        return $this->elasticSearchName;
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function getName()
81
    {
82
        return $this->name;
83
    }
84
85
    /**
86
     * @return array
87
     */
88 3
    public function getSettings()
89
    {
90 3
        return $this->settings;
91
    }
92
93
    /**
94
     * @param string $typeName
95
     *
96
     * @return TypeConfig
97
     *
98
     * @throws \InvalidArgumentException
99
     */
100 1
    public function getType($typeName)
101
    {
102 1
        if (!array_key_exists($typeName, $this->types)) {
103
            throw new \InvalidArgumentException(sprintf('Type "%s" does not exist on index "%s"', $typeName, $this->name));
104
        }
105
106 1
        return $this->types[$typeName];
107
    }
108
109
    /**
110
     * @return \FOS\ElasticaBundle\Configuration\TypeConfig[]
111
     */
112 3
    public function getTypes()
113
    {
114 3
        return $this->types;
115
    }
116
117
    /**
118
     * @return boolean
119
     */
120 11
    public function isUseAlias()
121
    {
122 11
        return $this->useAlias;
123
    }
124
}
125