Completed
Push — master ( c8cd34...e54e2c )
by Nikola
11:06
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 122
Duplicated Lines 54.92 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 4
c 4
b 2
f 1
lcom 1
cbo 3
dl 67
loc 122
ccs 92
cts 92
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 16 1
B getUnderscoredBundlePrefixDefinition() 33 33 1
B getUnderscoredClassNamespacePrefixDefinition() 34 34 1
B getNamerCollectionDefinition() 0 29 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) 2016 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 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...
40 2
    {
41 6
        $node = new ArrayNodeDefinition('underscored_bundle_prefix');
42
43
        $node
44 6
            ->children()
45 6
                ->enumNode('case')
46 6
                    ->info('Which case to use, lowercase or uppercase. Default is lowercase.')
47 6
                    ->values(array('lowercase', 'uppercase'))
48 6
                    ->defaultValue('lowercase')
49 6
                ->end()
50 6
                ->booleanNode('joinTableFieldSuffix')
51 6
                    ->defaultTrue()
52 6
                    ->info('Join table will get field name suffix enabling you to have multiple many-to-many relations without stating explicitly table names.')
53 6
                ->end()
54 6
                ->arrayNode('map')
55 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.')
56 6
                    ->useAttributeAsKey('name')
57 6
                    ->prototype('scalar')->end()
58 6
                ->end()
59 6
                ->arrayNode('whitelist')
60 6
                    ->info('Define for which bundles to apply prefixes.')
61 6
                    ->prototype('scalar')->end()
62 6
                ->end()
63 6
                ->arrayNode('blacklist')
64 6
                    ->info('Define for which bundles not to apply prefixes.')
65 6
                    ->prototype('scalar')->end()
66 6
                ->end()
67 6
            ->end()
68 6
        ->end();
69
70 6
        return $node;
71
    }
72
73 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...
74
    {
75 6
        $node = new ArrayNodeDefinition('underscored_class_namespace_prefix');
76
77
        $node
78 6
            ->children()
79 6
                ->enumNode('case')
80 6
                    ->info('Which case to use, lowercase or uppercase. Default is lowercase.')
81 6
                    ->values(array('lowercase', 'uppercase'))
82 6
                    ->defaultValue('lowercase')
83 6
                ->end()
84 6
                ->booleanNode('joinTableFieldSuffix')
85 6
                    ->defaultTrue()
86 6
                    ->info('Join table will get field name suffix enabling you to have multiple many-to-many relations without stating explicitly table names.')
87 6
                ->end()
88 6
                ->arrayNode('map')
89 6
                    ->requiresAtLeastOneElement()
90 6
                    ->info('Map of FQCNs prefixes and table prefixes to use for naming.')
91 6
                    ->useAttributeAsKey('name')
92 6
                    ->prototype('scalar')->end()
93 6
                ->end()
94 6
                ->arrayNode('whitelist')
95 6
                    ->info('Define for which FQCNs prefixes table prefixes should be applied.')
96 6
                    ->prototype('scalar')->end()
97 6
                ->end()
98 6
                ->arrayNode('blacklist')
99 6
                    ->info('Define for which FQCNs prefixes not to apply table prefixes.')
100 6
                    ->prototype('scalar')->end()
101 6
                ->end()
102 6
            ->end()
103 6
        ->end();
104
105 6
        return $node;
106
    }
107
108 6
    protected function getNamerCollectionDefinition()
109
    {
110 6
        $node = new ArrayNodeDefinition('namer_collection');
111
112
        $node
113 6
            ->children()
114 6
                ->scalarNode('default')
115 6
                    ->info('Default namer which will determine default name.')
116 6
                    ->defaultValue('doctrine.orm.naming_strategy.underscore')
117 6
                ->end()
118 6
                ->arrayNode('namers')
119 6
                    ->requiresAtLeastOneElement()
120 6
                    ->info('Concurrent namers (referenced as service) which will propose different name, if applicable.')
121 6
                    ->prototype('scalar')->end()
122 6
                ->end()
123 6
                ->enumNode('concatenation')
124 6
                    ->info('How to concatenate join table names and join key column names considering that different naming strategies can be included in mix.')
125 6
                    ->values(array(NamerCollection::UNDERSCORE, NamerCollection::NOTHING, NamerCollection::UCFIRST))
126 6
                    ->defaultValue(NamerCollection::UNDERSCORE)
127 6
                ->end()
128 6
                ->booleanNode('joinTableFieldSuffix')
129 6
                    ->defaultTrue()
130 6
                    ->info('Join table will get field name suffix enabling you to have multiple many-to-many relations without stating explicitly table names.')
131 6
                ->end()
132 6
            ->end()
133 6
        ->end();
134
135 6
        return $node;
136
    }
137
138
}
139