Completed
Pull Request — master (#45)
by Jan
19:37
created

Configuration::addResourcesSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace Lakion\CmsPlugin\DependencyInjection;
4
5
use Lakion\CmsPlugin\Document\CustomBlock;
6
use Lakion\CmsPlugin\Document\ProductBlock;
7
use Lakion\CmsPlugin\Document\Route;
8
use Lakion\CmsPlugin\Document\StaticContent;
9
use Lakion\CmsPlugin\Document\StringBlock;
10
use Lakion\CmsPlugin\Form\Type\CustomBlockType;
11
use Lakion\CmsPlugin\Form\Type\ProductBlockType;
12
use Lakion\CmsPlugin\Form\Type\RouteType;
13
use Lakion\CmsPlugin\Form\Type\StaticContentType;
14
use Lakion\CmsPlugin\Form\Type\StringBlockType;
15
use Lakion\CmsPlugin\Repository\StaticContentRepository;
16
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
17
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
18
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
19
use Symfony\Component\Config\Definition\ConfigurationInterface;
20
21
final class Configuration implements ConfigurationInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getConfigTreeBuilder()
27
    {
28
        $treeBuilder = new TreeBuilder();
29
        $rootNode = $treeBuilder->root('lakion_cms');
30
31
        $this->addResourcesSection($rootNode->children());
32
33
        return $treeBuilder;
34
    }
35
36
    /**
37
     * @param NodeBuilder $rootNodeBuilder
38
     */
39
    private function addResourcesSection(NodeBuilder $rootNodeBuilder)
40
    {
41
        $resourcesNodeBuilder = $rootNodeBuilder->arrayNode('resources')->addDefaultsIfNotSet()->children();
42
43
        $this->addResourcesCustomBlockSection($resourcesNodeBuilder);
44
        $this->addResourcesProductBlockSection($resourcesNodeBuilder);
45
        $this->addResourcesRouteSection($resourcesNodeBuilder);
46
        $this->addResourcesStaticContentSection($resourcesNodeBuilder);
47
        $this->addResourcesStringBlockSection($resourcesNodeBuilder);
48
    }
49
50
    /**
51
     * @param NodeBuilder $resourcesNodeBuilder
52
     */
53 View Code Duplication
    private function addResourcesCustomBlockSection(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...
54
    {
55
        $resourcesNodeBuilder
56
            ->arrayNode('custom_block')
57
                ->addDefaultsIfNotSet()
58
                ->children()
59
                    ->arrayNode('classes')
60
                        ->addDefaultsIfNotSet()
61
                        ->children()
62
                            ->scalarNode('model')->defaultValue(CustomBlock::class)->cannotBeEmpty()->end()
63
                            ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
64
                            ->scalarNode('repository')->cannotBeEmpty()->end()
65
                            ->scalarNode('form')->defaultValue(CustomBlockType::class)->cannotBeEmpty()->end()
66
        ;
67
    }
68
69
    /**
70
     * @param NodeBuilder $resourcesNodeBuilder
71
     */
72 View Code Duplication
    private function addResourcesProductBlockSection(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...
73
    {
74
        $resourcesNodeBuilder
75
            ->arrayNode('product_block')
76
                ->addDefaultsIfNotSet()
77
                ->children()
78
                    ->arrayNode('classes')
79
                        ->addDefaultsIfNotSet()
80
                        ->children()
81
                            ->scalarNode('model')->defaultValue(ProductBlock::class)->cannotBeEmpty()->end()
82
                            ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
83
                            ->scalarNode('repository')->cannotBeEmpty()->end()
84
                            ->scalarNode('form')->defaultValue(ProductBlockType::class)->cannotBeEmpty()->end()
85
        ;
86
    }
87
88
    /**
89
     * @param NodeBuilder $resourcesNodeBuilder
90
     */
91 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...
92
    {
93
        $resourcesNodeBuilder
94
            ->arrayNode('route')
95
                ->addDefaultsIfNotSet()
96
                ->children()
97
                    ->arrayNode('classes')
98
                        ->addDefaultsIfNotSet()
99
                        ->children()
100
                            ->scalarNode('model')->defaultValue(Route::class)->cannotBeEmpty()->end()
101
                            ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
102
                            ->scalarNode('repository')->cannotBeEmpty()->end()
103
                            ->scalarNode('form')->defaultValue(RouteType::class)->cannotBeEmpty()->end()
104
        ;
105
    }
106
107
    /**
108
     * @param NodeBuilder $resourcesNodeBuilder
109
     */
110
    private function addResourcesStaticContentSection(NodeBuilder $resourcesNodeBuilder)
111
    {
112
        $resourcesNodeBuilder
113
            ->arrayNode('static_content')
114
                ->addDefaultsIfNotSet()
115
                ->children()
116
                    ->arrayNode('classes')
117
                        ->addDefaultsIfNotSet()
118
                        ->children()
119
                            ->scalarNode('model')->defaultValue(StaticContent::class)->cannotBeEmpty()->end()
120
                            ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
121
                            ->scalarNode('repository')->defaultValue(StaticContentRepository::class)->cannotBeEmpty()->end()
122
                            ->scalarNode('form')->defaultValue(StaticContentType::class)->cannotBeEmpty()->end()
123
        ;
124
    }
125
126
    /**
127
     * @param NodeBuilder $resourcesNodeBuilder
128
     */
129 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...
130
    {
131
        $resourcesNodeBuilder
132
            ->arrayNode('string_block')
133
                ->addDefaultsIfNotSet()
134
                ->children()
135
                    ->arrayNode('classes')
136
                        ->addDefaultsIfNotSet()
137
                        ->children()
138
                            ->scalarNode('model')->defaultValue(StringBlock::class)->cannotBeEmpty()->end()
139
                            ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
140
                            ->scalarNode('repository')->cannotBeEmpty()->end()
141
                            ->scalarNode('form')->defaultValue(StringBlockType::class)->cannotBeEmpty()->end()
142
        ;
143
    }
144
}
145