Completed
Push — master ( 3182b0...115a8b )
by Arkadiusz
11s
created

Configuration   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 35.71 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 1
cbo 3
dl 30
loc 84
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 9 1
A addResourcesSection() 0 8 1
A addResourcesRouteSection() 15 15 1
A addResourcesStaticContentSection() 0 15 1
A addResourcesStringBlockSection() 15 15 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 Lakion\SyliusCmsBundle\DependencyInjection;
4
5
use Lakion\SyliusCmsBundle\Document\Route;
6
use Lakion\SyliusCmsBundle\Document\StaticContent;
7
use Lakion\SyliusCmsBundle\Document\StringBlock;
8
use Lakion\SyliusCmsBundle\Form\Type\RouteType;
9
use Lakion\SyliusCmsBundle\Form\Type\StaticContentType;
10
use Lakion\SyliusCmsBundle\Form\Type\StringBlockType;
11
use Lakion\SyliusCmsBundle\Repository\StaticContentRepository;
12
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
13
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
14
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
18
final class Configuration implements ConfigurationInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function getConfigTreeBuilder()
24
    {
25
        $treeBuilder = new TreeBuilder();
26
        $rootNode = $treeBuilder->root('lakion_sylius_cms');
27
28
        $this->addResourcesSection($rootNode->children());
29
30
        return $treeBuilder;
31
    }
32
33
    /**
34
     * @param NodeBuilder $rootNodeBuilder
35
     */
36
    private function addResourcesSection(NodeBuilder $rootNodeBuilder)
37
    {
38
        $resourcesNodeBuilder = $rootNodeBuilder->arrayNode('resources')->addDefaultsIfNotSet()->children();
39
40
        $this->addResourcesRouteSection($resourcesNodeBuilder);
41
        $this->addResourcesStaticContentSection($resourcesNodeBuilder);
42
        $this->addResourcesStringBlockSection($resourcesNodeBuilder);
43
    }
44
45
    /**
46
     * @param NodeBuilder $resourcesNodeBuilder
47
     */
48 View Code Duplication
    private function addResourcesRouteSection(NodeBuilder $resourcesNodeBuilder)
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...
49
    {
50
        $resourcesNodeBuilder
51
            ->arrayNode('route')
52
                ->addDefaultsIfNotSet()
53
                ->children()
54
                    ->arrayNode('classes')
55
                        ->addDefaultsIfNotSet()
56
                        ->children()
57
                            ->scalarNode('model')->defaultValue(Route::class)->cannotBeEmpty()->end()
58
                            ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
59
                            ->scalarNode('repository')->cannotBeEmpty()->end()
60
                            ->scalarNode('form')->defaultValue(RouteType::class)->cannotBeEmpty()->end()
61
        ;
62
    }
63
64
    /**
65
     * @param NodeBuilder $resourcesNodeBuilder
66
     */
67
    private function addResourcesStaticContentSection(NodeBuilder $resourcesNodeBuilder)
68
    {
69
        $resourcesNodeBuilder
70
            ->arrayNode('static_content')
71
                ->addDefaultsIfNotSet()
72
                ->children()
73
                    ->arrayNode('classes')
74
                        ->addDefaultsIfNotSet()
75
                        ->children()
76
                            ->scalarNode('model')->defaultValue(StaticContent::class)->cannotBeEmpty()->end()
77
                            ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
78
                            ->scalarNode('repository')->defaultValue(StaticContentRepository::class)->cannotBeEmpty()->end()
79
                            ->scalarNode('form')->defaultValue(StaticContentType::class)->cannotBeEmpty()->end()
80
        ;
81
    }
82
83
    /**
84
     * @param NodeBuilder $resourcesNodeBuilder
85
     */
86 View Code Duplication
    private function addResourcesStringBlockSection(NodeBuilder $resourcesNodeBuilder)
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...
87
    {
88
        $resourcesNodeBuilder
89
            ->arrayNode('string_block')
90
                ->addDefaultsIfNotSet()
91
                ->children()
92
                    ->arrayNode('classes')
93
                        ->addDefaultsIfNotSet()
94
                        ->children()
95
                            ->scalarNode('model')->defaultValue(StringBlock::class)->cannotBeEmpty()->end()
96
                            ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
97
                            ->scalarNode('repository')->cannotBeEmpty()->end()
98
                            ->scalarNode('form')->defaultValue(StringBlockType::class)->cannotBeEmpty()->end()
99
        ;
100
    }
101
}
102