IndexTemplateManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 32
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIndexTemplate() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <https://friendsofsymfony.github.com/>
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\Index;
13
14
use Elastica\IndexTemplate;
15
16
/**
17
 * Class Index template manager.
18
 *
19
 * @author Dmitry Balabka <[email protected]>
20
 */
21
class IndexTemplateManager
22
{
23
    /**
24
     * Templates.
25
     *
26
     * @var array
27
     */
28
    private $templates;
29
30 8
    public function __construct(array $templates)
31
    {
32 8
        $this->templates = $templates;
33 8
    }
34
35
    /**
36
     * Gets an index template by its name.
37
     *
38
     * @param string $name Index template to return
39
     *
40
     * @return IndexTemplate
41
     *
42
     * @throws \InvalidArgumentException if no index template exists for the given name
43
     */
44 7
    public function getIndexTemplate($name)
45
    {
46 7
        if (!isset($this->templates[$name])) {
47 2
            throw new \InvalidArgumentException(\sprintf('The index template "%s" does not exist', $name));
48
        }
49
50 5
        return $this->templates[$name];
51
    }
52
}
53