Completed
Push — master ( b86c68...476207 )
by Krzysztof
12:15 queued 09:59
created

Configuration   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 144
Duplicated Lines 59.03 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
c 4
b 0
f 0
lcom 1
cbo 3
dl 85
loc 144
ccs 74
cts 74
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 24 1
A getCriteriaCollectionNode() 14 14 1
A getBuilderCollectionNode() 14 14 1
A getSearcher() 15 15 1
A getContextNode() 14 14 1
A getCriteriaNode() 14 14 1
A getBuildersNode() 14 14 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 KGzocha\Bundle\SearcherBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * @author Krzysztof Gzocha <[email protected]>
11
 * @package KGzocha\Bundle\SearcherBundle\DependencyInjection
12
 */
13
class Configuration implements ConfigurationInterface
14
{
15
    const SEARCHER_CLASS = 'KGzocha\Searcher\Searcher';
16
    const WRAPPER_CLASS = 'KGzocha\Searcher\WrappedResultsSearcher';
17
    const CRITERIA_COLLECTION_CLASS = 'KGzocha\Searcher\Criteria\Collection\NamedCriteriaCollection';
18
    const BUILDER_COLLECTION_CLASS = 'KGzocha\Searcher\CriteriaBuilder\Collection\CriteriaBuilderCollection';
19
20
    /**
21
     * @inheritdoc
22
     */
23 2
    public function getConfigTreeBuilder()
24
    {
25 2
        $treeBuilder = new TreeBuilder();
26 2
        $rootNode = $treeBuilder->root('k_gzocha_searcher');
27
28
        $rootNode
29 2
            ->canBeUnset(true)
30 2
            ->children()
31 2
                ->arrayNode('contexts')
32 2
                ->canBeUnset(true)
33 2
                ->useAttributeAsKey('context_id')
34 2
                ->prototype('array')
35 2
                ->children()
36 2
                    ->append($this->getCriteriaCollectionNode())
37 2
                    ->append($this->getBuilderCollectionNode())
38 2
                    ->append($this->getCriteriaNode())
39 2
                    ->append($this->getBuildersNode())
40 2
                    ->append($this->getSearcher())
41 2
                    ->append($this->getContextNode())
42 2
                ->end()
43 2
            ->end();
44
45 2
        return $treeBuilder;
46
    }
47
48
    /**
49
     * @return ArrayNodeDefinition
50
     */
51 2 View Code Duplication
    protected function getCriteriaCollectionNode()
52
    {
53 2
        $node = new ArrayNodeDefinition('criteria_collection');
54
55
        $node
56 2
            ->addDefaultsIfNotSet()
57 2
            ->canBeUnset()
58 2
            ->children()
59 2
                ->scalarNode('class')->defaultValue(self::CRITERIA_COLLECTION_CLASS)->end()
60 2
                ->scalarNode('service')->defaultValue(null)->end()
61 2
            ->end();
62
63 2
        return $node;
64
    }
65
66
    /**
67
     * @return ArrayNodeDefinition
68
     */
69 2 View Code Duplication
    protected function getBuilderCollectionNode()
70
    {
71 2
        $node = new ArrayNodeDefinition('builder_collection');
72
73
        $node
74 2
            ->addDefaultsIfNotSet()
75 2
            ->canBeUnset()
76 2
            ->children()
77 2
                ->scalarNode('class')->defaultValue(self::BUILDER_COLLECTION_CLASS)->end()
78 2
                ->scalarNode('service')->defaultValue(null)->end()
79 2
            ->end();
80
81 2
        return $node;
82
    }
83
84
    /**
85
     * @return ArrayNodeDefinition
86
     */
87 2 View Code Duplication
    protected function getSearcher()
88
    {
89 2
        $node = new ArrayNodeDefinition('searcher');
90
91
        $node
92 2
            ->addDefaultsIfNotSet()
93 2
            ->canBeUnset()
94 2
            ->children()
95 2
                ->scalarNode('class')->defaultValue(self::SEARCHER_CLASS)->end()
96 2
                ->scalarNode('service')->defaultValue(null)->end()
97 2
                ->scalarNode('wrapper_class')->defaultValue(self::WRAPPER_CLASS)->end()
98 2
            ->end();
99
100 2
        return $node;
101
    }
102
103
    /**
104
     * @return ArrayNodeDefinition
105
     */
106 2 View Code Duplication
    protected function getContextNode()
107
    {
108 2
        $node = new ArrayNodeDefinition('context');
109
110
        $node
111 2
            ->addDefaultsIfNotSet()
112 2
            ->canBeUnset()
113 2
            ->children()
114 2
                ->scalarNode('class')->defaultValue(null)->end()
115 2
                ->scalarNode('service')->defaultValue(null)->end()
116 2
            ->end();
117
118 2
        return $node;
119
    }
120
121
    /**
122
     * @return ArrayNodeDefinition
123
     */
124 2 View Code Duplication
    protected function getCriteriaNode()
125
    {
126 2
        $node = new ArrayNodeDefinition('criteria');
127
128
        $node
129 2
            ->prototype('array')
130 2
            ->children()
131 2
                ->scalarNode('class')->defaultValue(null)->end()
132 2
                ->scalarNode('service')->defaultValue(null)->end()
133 2
                ->scalarNode('name')->cannotBeEmpty()->isRequired()->end()
134 2
            ->end();
135
136 2
        return $node;
137
    }
138
139
    /**
140
     * @return ArrayNodeDefinition
141
     */
142 2 View Code Duplication
    protected function getBuildersNode()
143
    {
144 2
        $node = new ArrayNodeDefinition('builders');
145
146
        $node
147 2
            ->prototype('array')
148 2
            ->children()
149 2
                ->scalarNode('class')->defaultValue(null)->end()
150 2
                ->scalarNode('service')->defaultValue(null)->end()
151 2
                ->scalarNode('name')->cannotBeEmpty()->isRequired()->end()
152 2
            ->end();
153
154 2
        return $node;
155
    }
156
}
157