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

Extension   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 119
Duplicated Lines 38.66 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 93.1%

Importance

Changes 4
Bugs 2 Features 2
Metric Value
wmc 13
c 4
b 2
f 2
lcom 1
cbo 7
dl 46
loc 119
ccs 54
cts 58
cp 0.931
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 12 1
B configureUnderscoredBundlePrefixNamer() 23 23 4
B configureUnderscoredClassNamespacePrefixNamer() 23 23 4
A configureNamerCollection() 0 23 3
A getAlias() 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
 * 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 Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
14
use Symfony\Component\DependencyInjection\Reference;
15
use Symfony\Component\HttpKernel\DependencyInjection\Extension as BaseExtension;
16
use Symfony\Component\Config\FileLocator;
17
18
class Extension extends BaseExtension
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23 6
    public function load(array $config, ContainerBuilder $container)
24
    {
25 6
        $configuration = new Configuration();
26 6
        $config = $this->processConfiguration($configuration, $config);
27
28 6
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
29 6
        $loader->load('services.xml');
30
31 6
        $this->configureUnderscoredBundlePrefixNamer($container, $config);
32 6
        $this->configureUnderscoredClassNamespacePrefixNamer($container, $config);
33 6
        $this->configureNamerCollection($container, $config);
34 6
    }
35
36
    /**
37
     * Configure 'run_open_code.doctrine.orm.naming_strategy.underscored_bundle_prefix' naming strategy.
38
     *
39
     * @param ContainerBuilder $container
40
     * @param array $config
41
     * @return Extension $this
42
     */
43 6 View Code Duplication
    private function configureUnderscoredBundlePrefixNamer(ContainerBuilder $container, array $config)
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...
44
    {
45
        if (
46 6
            $container->hasDefinition('run_open_code.doctrine.orm.naming_strategy.underscored_bundle_prefix')
47 6
            &&
48 6
            isset($config['underscored_bundle_prefix'])
49 6
        ) {
50 2
            $definition = $container->getDefinition('run_open_code.doctrine.orm.naming_strategy.underscored_bundle_prefix');
51
52 2
            if ($config['underscored_bundle_prefix']['case'] == 'uppercase') {
53
                $config['underscored_bundle_prefix']['case'] = CASE_UPPER;
54
            } else {
55 2
                $config['underscored_bundle_prefix']['case'] = CASE_LOWER;
56
            }
57
58 2
            $args = $definition->getArguments();
59 2
            $args[1] = $config['underscored_bundle_prefix'];
60
61 2
            $definition->setArguments($args);
62 2
        }
63
64 6
        return $this;
65
    }
66
67
    /**
68
     * Configure 'run_open_code.doctrine.orm.naming_strategy.underscored_class_namespace_prefix' naming strategy.
69
     *
70
     * @param ContainerBuilder $container
71
     * @param array $config
72
     * @return Extension $this
73
     */
74 6 View Code Duplication
    private function configureUnderscoredClassNamespacePrefixNamer(ContainerBuilder $container, array $config)
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...
75
    {
76
        if (
77 6
            $container->hasDefinition('run_open_code.doctrine.orm.naming_strategy.underscored_class_namespace_prefix')
78 6
            &&
79 6
            isset($config['underscored_class_namespace_prefix'])
80 6
        ) {
81 2
            $definition = $container->getDefinition('run_open_code.doctrine.orm.naming_strategy.underscored_class_namespace_prefix');
82
83 2
            if ($config['underscored_class_namespace_prefix']['case'] == 'uppercase') {
84
                $config['underscored_class_namespace_prefix']['case'] = CASE_UPPER;
85
            } else {
86 2
                $config['underscored_class_namespace_prefix']['case'] = CASE_LOWER;
87
            }
88
89 2
            $args = $definition->getArguments();
90 2
            $args[0] = $config['underscored_class_namespace_prefix'];
91
92 2
            $definition->setArguments($args);
93 2
        }
94
95 6
        return $this;
96
    }
97
98
    /**
99
     * Configure 'run_open_code.doctrine.orm.naming_strategy.namer_collection' naming strategy.
100
     *
101
     * @param ContainerBuilder $container
102
     * @param array $config
103
     * @return Extension $this
104
     */
105 6
    private function configureNamerCollection(ContainerBuilder $container, array $config)
106
    {
107
        if (
108 6
            $container->hasDefinition('run_open_code.doctrine.orm.naming_strategy.namer_collection')
109 6
            &&
110 6
            isset($config['namer_collection'])
111 6
        ) {
112 2
            $definition = $container->getDefinition('run_open_code.doctrine.orm.naming_strategy.namer_collection');
113
114 2
            $definition->setArguments(array(
115 2
                new Reference($config['namer_collection']['default']),
116 2
                array_map(function($namerId) {
117 2
                    return new Reference($namerId);
118 2
                }, $config['namer_collection']['namers']),
119
                array(
120 2
                    'concatenation' => $config['namer_collection']['concatenation'],
121 2
                    'joinTableFieldSuffix' => $config['namer_collection']['joinTableFieldSuffix']
122 2
                )
123 2
            ));
124 2
        }
125
126 6
        return $this;
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132 6
    public function getAlias()
133
    {
134 6
        return "run_open_code_doctrine_naming_strategy";
135
    }
136
}
137