Completed
Pull Request — master (#917)
by Dmitry
08:52
created

ConfigManager::hasIndexConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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
     * @var IndexTemplateConfig[]
26
     */
27
    private $indexTemplates = array();
28
29
    /**
30
     * @param Source\SourceInterface[] $indexSources
31
     * @param Source\SourceInterface[] $indexTemplateSources
32
     */
33
    public function __construct(array $indexSources, array $indexTemplateSources)
34
    {
35
        foreach ($indexSources as $source) {
36
            $this->indexes = array_merge($source->getConfiguration(), $this->indexes);
37
        }
38
        foreach ($indexTemplateSources as $source) {
39
            $this->indexTemplates = array_merge($source->getConfiguration(), $this->indexTemplates);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge($source->get... $this->indexTemplates) of type array<integer,object<FOS...n\IndexTemplateConfig>> is incompatible with the declared type array<integer,object<FOS...n\IndexTemplateConfig>> of property $indexTemplates.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
        }
41
    }
42
43
    public function getIndexConfiguration($indexName)
44
    {
45
        if (!$this->hasIndexConfiguration($indexName)) {
46
            throw new \InvalidArgumentException(sprintf('Index with name "%s" is not configured.', $indexName));
47
        }
48
49
        return $this->indexes[$indexName];
50
    }
51
52
    /**
53
     * @param string $indexTemplateName
54
     *
55
     * @return IndexTemplateConfig
56
     */
57
    public function getIndexTemplateConfiguration($indexTemplateName)
58
    {
59
        if (!$this->hasIndexTemplateConfiguration($indexTemplateName)) {
60
            throw new \InvalidArgumentException(sprintf('Index template with name "%s" is not configured.', $indexTemplateName));
61
        }
62
63
        return $this->indexTemplates[$indexTemplateName];
64
    }
65
66
    public function getIndexNames()
67
    {
68
        return array_keys($this->indexes);
69
    }
70
71
    public function getIndexTemplatesNames()
72
    {
73
        return array_keys($this->indexTemplates);
74
    }
75
76
    public function getTypeConfiguration($indexName, $typeName)
77
    {
78
        $index = $this->getIndexConfiguration($indexName);
79
        $type = $index->getType($typeName);
80
81
        if (!$type) {
82
            throw new \InvalidArgumentException(sprintf('Type with name "%s" on index "%s" is not configured', $typeName, $indexName));
83
        }
84
85
        return $type;
86
    }
87
88
    public function hasIndexConfiguration($indexName)
89
    {
90
        return isset($this->indexes[$indexName]);
91
    }
92
93
    public function hasIndexTemplateConfiguration($indexTemplateName)
94
    {
95
        return isset($this->indexTemplates[$indexTemplateName]);
96
    }
97
}
98