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

IndexTemplateConfig   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 28.95 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 11
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 4
A getTemplate() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 extends IndexConfigAbstract
11
{
12
    /**
13
     * Index name pattern
14
     *
15
     * @var string
16
     */
17
    private $template;
18
19
    /**
20
     * Constructor expects an array as generated by the Container Configuration builder.
21
     *
22
     * @param string       $name
23
     * @param TypeConfig[] $types
24
     * @param array        $config
25
     */
26 View Code Duplication
    public function __construct($name, array $types, array $config)
27
    {
28
        $this->elasticSearchName = isset($config['elasticSearchName']) ? $config['elasticSearchName'] : $name;
29
        $this->name = $name;
30
        $this->settings = isset($config['settings']) ? $config['settings'] : array();
31
        if (!isset($config['template'])) {
32
            throw new \InvalidArgumentException('Index template value must be set');
33
        }
34
        $this->template = $config['template'];
35
        $this->types = $types;
36
    }
37
38
    /**
39
     * Gets index name pattern
40
     *
41
     * @return string
42
     */
43
    public function getTemplate()
44
    {
45
        return $this->template;
46
    }
47
}
48