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

IndexTemplateConfig::__construct()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 9
cts 9
cp 1
rs 9.9
c 0
b 0
f 0
cc 4
nc 8
nop 3
crap 4
1
<?php
2
3
namespace FOS\ElasticaBundle\Configuration;
4
5
/**
6
 * Index template configuration class
7
 *
8
 * @author Dmitry Balabka <[email protected]>
9
 */
10
class IndexTemplateConfig implements IndexConfigInterface
11
{
12
    use IndexConfigTrait;
13
14
    /**
15
     * Index name pattern
16
     *
17
     * @var string
18
     */
19
    private $template;
20
21
    /**
22
     * Constructor expects an array as generated by the Container Configuration builder.
23
     *
24
     * @param string       $name
25
     * @param TypeConfig[] $types
26
     * @param array        $config
27
     */
28 9 View Code Duplication
    public function __construct($name, array $types, array $config)
29
    {
30 9
        $this->elasticSearchName = isset($config['elasticSearchName']) ? $config['elasticSearchName'] : $name;
31 9
        $this->name = $name;
32 9
        $this->settings = isset($config['settings']) ? $config['settings'] : array();
33 9
        if (!isset($config['template'])) {
34 1
            throw new \InvalidArgumentException('Index template value must be set');
35
        }
36 8
        $this->template = $config['template'];
37 8
        $this->types = $types;
38 8
    }
39
40
    /**
41
     * Gets index name pattern
42
     *
43
     * @return string
44
     */
45 7
    public function getTemplate()
46
    {
47 7
        return $this->template;
48
    }
49
}
50