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

IndexTemplateConfig   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 27.5 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 11
loc 40
ccs 11
cts 11
cp 1
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 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