Completed
Pull Request — master (#1343)
by Dmitry
06:11
created

IndexTemplateManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 32
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
 * This file is part of the OpCart software.
4
 *
5
 * (c) 2018, ecentria group, Inc
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace FOS\ElasticaBundle\Index;
12
13
use Elastica\IndexTemplate;
14
15
/**
16
 * Class Index template manager
17
 *
18
 * @author Dmitry Balabka <[email protected]>
19
 */
20
class IndexTemplateManager
21
{
22
    /**
23
     * Templates
24
     *
25
     * @var array
26
     */
27
    private $templates;
28
29
    public function __construct(array $templates)
30
    {
31
        $this->templates = $templates;
32
    }
33
34
    /**
35
     * Gets an index template by its name.
36
     *
37
     * @param string $name Index template to return
38
     *
39
     * @return IndexTemplate
40
     *
41
     * @throws \InvalidArgumentException if no index template exists for the given name
42
     */
43
    public function getIndexTemplate($name = null)
44
    {
45
        if (!isset($this->templates[$name])) {
46
            throw new \InvalidArgumentException(sprintf('The index template "%s" does not exist', $name));
47
        }
48
49
        return $this->templates[$name];
50
    }
51
}
52