Completed
Push — master ( fef1f2...3eb154 )
by Tim
7s
created

ConfigManager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 85%
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 48
ccs 17
cts 20
cp 0.85
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasIndexConfiguration() 0 4 1
A getIndexConfiguration() 0 8 2
A getTypeConfiguration() 0 11 2
A __construct() 0 6 2
A getIndexNames() 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
/**
15
 * Central manager for index and type configuration.
16
 */
17
class ConfigManager implements ManagerInterface
18
{
19
    /**
20
     * @var IndexConfig[]
21
     */
22
    private $indexes = array();
23
24
    /**
25
     * @param Source\SourceInterface[] $sources
26
     */
27 6
    public function __construct(array $sources)
28
    {
29 6
        foreach ($sources as $source) {
30 6
            $this->indexes = array_merge($source->getConfiguration(), $this->indexes);
31 6
        }
32 6
    }
33
34 6
    public function getIndexConfiguration($indexName)
35
    {
36 6
        if (!$this->hasIndexConfiguration($indexName)) {
37
            throw new \InvalidArgumentException(sprintf('Index with name "%s" is not configured.', $indexName));
38
        }
39
40 6
        return $this->indexes[$indexName];
41
    }
42
43 1
    public function getIndexNames()
44 1
    {
45
        return array_keys($this->indexes);
46
    }
47
48 2
    public function getTypeConfiguration($indexName, $typeName)
49
    {
50 2
        $index = $this->getIndexConfiguration($indexName);
51 2
        $type = $index->getType($typeName);
52
53 2
        if (!$type) {
54
            throw new \InvalidArgumentException(sprintf('Type with name "%s" on index "%s" is not configured', $typeName, $indexName));
55
        }
56
57 2
        return $type;
58
    }
59
60 6
    public function hasIndexConfiguration($indexName)
61
    {
62 6
        return isset($this->indexes[$indexName]);
63
    }
64
}
65