Completed
Push — master ( 690b6b...6753b6 )
by Nikola
05:20
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 171
Duplicated Lines 54.39 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 93
loc 171
ccs 114
cts 114
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 16 1
B getUnderscoredBundlePrefixDefinition() 46 46 1
A getUnderscoredClassNamespacePrefixDefinition() 47 47 1
B getNamerCollectionDefinition() 0 37 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
 * This file is part of the Doctrine Naming Strategy Bundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\DoctrineNamingStrategy\DependencyInjection;
11
12
use RunOpenCode\Bundle\DoctrineNamingStrategy\NamingStrategy\NamerCollection;
13
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
class Configuration implements ConfigurationInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 6
    public function getConfigTreeBuilder()
23
    {
24 6
        $treeBuilder = new TreeBuilder();
25
26 6
        $rootNode = $treeBuilder->root('run_open_code_doctrine_naming_strategy');
27
28
        $rootNode
29 6
            ->children()
30 6
                ->append($this->getUnderscoredBundlePrefixDefinition())
31 6
                ->append($this->getUnderscoredClassNamespacePrefixDefinition())
32 6
                ->append($this->getNamerCollectionDefinition())
33 6
            ->end()
34 6
        ->end();
35
36 6
        return $treeBuilder;
37
    }
38
39
    /**
40
     * Configure underscored bundle prefix naming strategy
41
     *
42
     * @return ArrayNodeDefinition
43
     */
44 6 View Code Duplication
    protected function getUnderscoredBundlePrefixDefinition()
0 ignored issues
show
Duplication introduced by
This method 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...
45
    {
46 6
        $node = new ArrayNodeDefinition('underscored_bundle_prefix');
47
48
        $node
49 6
            ->addDefaultsIfNotSet()
50 6
            ->children()
51 6
                ->enumNode('case')
52 6
                    ->info('Which case to use, lowercase or uppercase. Default is lowercase.')
53 6
                    ->values(array('lowercase', 'uppercase'))
54 6
                    ->defaultValue('lowercase')
55 6
                ->end()
56 6
                ->booleanNode('join_table_field_suffix')
57 6
                    ->defaultTrue()
58 6
                    ->info('Join table will get field name suffix enabling you to have multiple many-to-many relations without stating explicitly table names.')
59 6
                ->end()
60 6
                ->arrayNode('map')
61 6
                    ->info('Map of short bundle names and prefixes, if you do not want to use full bundle name in prefix. Useful when bundle name is too long, considering that, per example, MySQL has 60 chars table name limit.')
62 6
                    ->useAttributeAsKey('bundle')
63 6
                    ->prototype('scalar')->end()
64 6
                ->end()
65 6
                ->arrayNode('whitelist')
66 6
                    ->beforeNormalization()
67 6
                        ->ifString()
68
                        ->then(function ($value) {
69
                            return [$value];
70 6
                        })
71 6
                        ->end()
72 6
                    ->info('Define for which bundles to apply prefixes.')
73 6
                    ->prototype('scalar')->end()
74 6
                ->end()
75 6
                ->arrayNode('blacklist')
76 6
                    ->beforeNormalization()
77 6
                        ->ifString()
78
                        ->then(function ($value) {
79 1
                            return [$value];
80 6
                        })
81 6
                    ->end()
82 6
                    ->info('Define for which bundles not to apply prefixes.')
83 6
                    ->prototype('scalar')->end()
84 6
                ->end()
85 6
            ->end()
86 6
        ->end();
87
88 6
        return $node;
89
    }
90
91
    /**
92
     * Configure underscored class namespace prefix naming strategy
93
     *
94
     * @return ArrayNodeDefinition
95
     */
96 6 View Code Duplication
    protected function getUnderscoredClassNamespacePrefixDefinition()
0 ignored issues
show
Duplication introduced by
This method 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...
97
    {
98 6
        $node = new ArrayNodeDefinition('underscored_class_namespace_prefix');
99
100
        $node
101 6
            ->addDefaultsIfNotSet()
102 6
            ->children()
103 6
                ->enumNode('case')
104 6
                    ->info('Which case to use, lowercase or uppercase. Default is lowercase.')
105 6
                    ->values(array('lowercase', 'uppercase'))
106 6
                    ->defaultValue('lowercase')
107 6
                ->end()
108 6
                ->booleanNode('join_table_field_suffix')
109 6
                    ->defaultTrue()
110 6
                    ->info('Join table will get field name suffix enabling you to have multiple many-to-many relations without stating explicitly table names.')
111 6
                ->end()
112 6
                ->arrayNode('map')
113 6
                    ->requiresAtLeastOneElement()
114 6
                    ->info('Map of FQCNs prefixes and table prefixes to use for naming.')
115 6
                    ->useAttributeAsKey('namespace')
116 6
                    ->prototype('scalar')->end()
117 6
                ->end()
118 6
                ->arrayNode('whitelist')
119 6
                    ->beforeNormalization()
120 6
                        ->ifString()
121
                        ->then(function ($value) {
122
                            return [$value];
123 6
                        })
124 6
                    ->end()
125 6
                    ->info('Define for which FQCNs prefixes table prefixes should be applied.')
126 6
                    ->prototype('scalar')->end()
127 6
                ->end()
128 6
                ->arrayNode('blacklist')
129 6
                    ->beforeNormalization()
130 6
                        ->ifString()
131
                        ->then(function ($value) {
132
                            return [$value];
133 6
                        })
134 6
                    ->end()
135 6
                    ->info('Define for which FQCNs prefixes not to apply table prefixes.')
136 6
                    ->prototype('scalar')->end()
137 6
                ->end()
138 6
            ->end()
139 6
        ->end();
140
141 6
        return $node;
142
    }
143
144
    /**
145
     * Configure namer collection
146
     *
147
     * @return ArrayNodeDefinition
148
     */
149 6
    protected function getNamerCollectionDefinition()
150
    {
151 6
        $node = new ArrayNodeDefinition('underscored_namer_collection');
152
153
        $node
154 6
            ->addDefaultsIfNotSet()
155 6
            ->fixXmlConfig('namer')
156
157 6
            ->children()
158 6
                ->scalarNode('default')
159 6
                    ->info('Default namer which will determine default name.')
160 6
                    ->defaultValue('doctrine.orm.naming_strategy.underscore')
161 6
                ->end()
162 6
                ->arrayNode('namers')
163 6
                    ->beforeNormalization()
164 6
                        ->ifString()
165 6
                        ->then(function ($value) {
166
                            return [$value];
167 6
                        })
168 6
                    ->end()
169 6
                    ->requiresAtLeastOneElement()
170 6
                    ->info('Concurrent namers (referenced as service) which will propose different name, if applicable.')
171 6
                    ->prototype('scalar')->end()
172 6
                    ->defaultValue([
173 6
                        'runopencode.doctrine.orm.naming_strategy.underscored_class_namespace_prefix',
174
                        'runopencode.doctrine.orm.naming_strategy.underscored_bundle_prefix',
175
                    ])
176 6
                ->end()
177 6
                ->booleanNode('join_table_field_suffix')
178 6
                    ->defaultTrue()
179 6
                    ->info('Join table will get field name suffix enabling you to have multiple many-to-many relations without stating explicitly table names.')
180 6
                ->end()
181 6
            ->end()
182 6
        ->end();
183
184 6
        return $node;
185
    }
186
187
}
188