IndexTemplateConfig::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

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