Completed
Push — master ( 8b30ba...c06433 )
by Karel
04:39
created

TemplateContainerSource   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 60
loc 60
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getConfiguration() 16 16 2
A getTypes() 16 16 3

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
/**
4
 * This file is part of the FOSElasticaBundle project.
5
 *
6
 * (c) Tim Nagel <[email protected]>
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\Source;
13
14
use FOS\ElasticaBundle\Configuration\IndexTemplateConfig;
15
use FOS\ElasticaBundle\Configuration\TypeConfig;
16
17
/**
18
 * Returns index and type configuration from the container.
19
 */
20 View Code Duplication
class TemplateContainerSource implements SourceInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
{
22
    /**
23
     * The internal container representation of information.
24
     *
25
     * @var array
26
     */
27
    private $configArray;
28
29 7
    public function __construct(array $configArray)
30
    {
31 7
        $this->configArray = $configArray;
32 7
    }
33
34
    /**
35
     * Should return all configuration available from the data source.
36
     *
37
     * @return IndexTemplateConfig[]
38
     */
39 7
    public function getConfiguration()
40
    {
41 7
        $indexes = array();
42 7
        foreach ($this->configArray as $config) {
43 6
            $types = $this->getTypes($config);
44 6
            $index = new IndexTemplateConfig($config['name'], $types, array(
45 6
                'elasticSearchName' => $config['elasticsearch_name'],
46 6
                'settings' => $config['settings'],
47 6
                'template' => $config['template'],
48
            ));
49
50 6
            $indexes[$config['name']] = $index;
51
        }
52
53 7
        return $indexes;
54
    }
55
56
    /**
57
     * Builds TypeConfig objects for each type.
58
     *
59
     * @param array $config
60
     *
61
     * @return array
62
     */
63 6
    protected function getTypes($config)
64
    {
65 6
        $types = array();
66
67 6
        if (isset($config['types'])) {
68 6
            foreach ($config['types'] as $typeConfig) {
69 6
                $types[$typeConfig['name']] = new TypeConfig(
70 6
                    $typeConfig['name'],
71 6
                    $typeConfig['mapping'],
72 6
                    $typeConfig['config']
73
                );
74
            }
75
        }
76
77 6
        return $types;
78
    }
79
}
80