Completed
Push — master ( 8b30ba...c06433 )
by Karel
04:39
created

IndexTemplateManager   A

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
namespace FOS\ElasticaBundle\Index;
4
5
use Elastica\IndexTemplate;
6
7
/**
8
 * Class Index template manager
9
 *
10
 * @author Dmitry Balabka <[email protected]>
11
 */
12
class IndexTemplateManager
13
{
14
    /**
15
     * Templates
16
     *
17
     * @var array
18
     */
19
    private $templates;
20
21 8
    public function __construct(array $templates)
22
    {
23 8
        $this->templates = $templates;
24 8
    }
25
26
    /**
27
     * Gets an index template by its name.
28
     *
29
     * @param string $name Index template to return
30
     *
31
     * @return IndexTemplate
32
     *
33
     * @throws \InvalidArgumentException if no index template exists for the given name
34
     */
35 7
    public function getIndexTemplate($name)
36
    {
37 7
        if (!isset($this->templates[$name])) {
38 2
            throw new \InvalidArgumentException(sprintf('The index template "%s" does not exist', $name));
39
        }
40
41 5
        return $this->templates[$name];
42
    }
43
}
44