Completed
Push — master ( 7c0075...645752 )
by Kamil
18:52
created

Configuration::addResourcesSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 55
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 9.7692
c 0
b 0
f 0
cc 1
eloc 52
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\CoreBundle\DependencyInjection;
13
14
use Sylius\Bundle\CoreBundle\Controller\ProductTaxonController;
15
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
16
use Sylius\Component\Core\Model\ProductImage;
17
use Sylius\Component\Core\Model\ProductImageInterface;
18
use Sylius\Component\Core\Model\ProductTaxon;
19
use Sylius\Component\Core\Model\ProductTaxonInterface;
20
use Sylius\Component\Core\Model\TaxonImage;
21
use Sylius\Component\Core\Model\TaxonImageInterface;
22
use Sylius\Component\Resource\Factory\Factory;
23
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
24
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
25
use Symfony\Component\Config\Definition\ConfigurationInterface;
26
27
final class Configuration implements ConfigurationInterface
28
{
29
    /**
30
     * @return TreeBuilder
31
     */
32
    public function getConfigTreeBuilder()
33
    {
34
        $treeBuilder = new TreeBuilder();
35
        $rootNode = $treeBuilder->root('sylius_core');
36
37
        $rootNode
38
            ->addDefaultsIfNotSet()
39
            ->children()
40
                ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
41
            ->end()
42
        ;
43
44
        $this->addResourcesSection($rootNode);
45
        $this->addSitemapSection($rootNode);
46
47
        return $treeBuilder;
48
    }
49
50
    /**
51
     * @param ArrayNodeDefinition $node
52
     */
53
    private function addResourcesSection(ArrayNodeDefinition $node)
54
    {
55
        $node
56
            ->children()
57
                ->arrayNode('resources')
58
                    ->addDefaultsIfNotSet()
59
                    ->children()
60
                        ->arrayNode('product_image')
61
                            ->addDefaultsIfNotSet()
62
                            ->children()
63
                                ->variableNode('options')->end()
64
                                ->arrayNode('classes')
65
                                    ->addDefaultsIfNotSet()
66
                                    ->children()
67
                                        ->scalarNode('model')->defaultValue(ProductImage::class)->cannotBeEmpty()->end()
68
                                        ->scalarNode('interface')->defaultValue(ProductImageInterface::class)->cannotBeEmpty()->end()
69
                                        ->scalarNode('factory')->defaultValue(Factory::class)->end()
70
                                    ->end()
71
                                ->end()
72
                            ->end()
73
                        ->end()
74
                        ->arrayNode('taxon_image')
75
                            ->addDefaultsIfNotSet()
76
                            ->children()
77
                                ->variableNode('options')->end()
78
                                ->arrayNode('classes')
79
                                    ->addDefaultsIfNotSet()
80
                                    ->children()
81
                                        ->scalarNode('model')->defaultValue(TaxonImage::class)->cannotBeEmpty()->end()
82
                                        ->scalarNode('interface')->defaultValue(TaxonImageInterface::class)->cannotBeEmpty()->end()
83
                                        ->scalarNode('factory')->defaultValue(Factory::class)->end()
84
                                    ->end()
85
                                ->end()
86
                            ->end()
87
                        ->end()
88
                        ->arrayNode('product_taxon')
89
                            ->addDefaultsIfNotSet()
90
                            ->children()
91
                                ->variableNode('options')->end()
92
                                ->arrayNode('classes')
93
                                    ->addDefaultsIfNotSet()
94
                                    ->children()
95
                                        ->scalarNode('model')->defaultValue(ProductTaxon::class)->cannotBeEmpty()->end()
96
                                        ->scalarNode('interface')->defaultValue(ProductTaxonInterface::class)->cannotBeEmpty()->end()
97
                                        ->scalarNode('controller')->defaultValue(ProductTaxonController::class)->cannotBeEmpty()->end()
98
                                        ->scalarNode('factory')->defaultValue(Factory::class)->end()
99
                                    ->end()
100
                                ->end()
101
                             ->end()
102
                        ->end()
103
                    ->end()
104
                ->end()
105
            ->end()
106
        ;
107
    }
108
109
    /**
110
     * @param ArrayNodeDefinition $node
111
     */
112
    private function addSitemapSection(ArrayNodeDefinition $node)
113
    {
114
        $node
115
            ->children()
116
                ->arrayNode('sitemap')
117
                    ->children()
118
                        ->scalarNode('template')->defaultValue('@SyliusCore/Sitemap/show.xml.twig')->end()
119
                    ->end()
120
                ->end()
121
            ->end()
122
        ;
123
    }
124
}
125