Completed
Push — sf5-deprecated-events ( 340c69...185721 )
by Kamil
06:54
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 9.0254
c 0
b 0
f 0
cc 1
nc 1
nop 0

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
declare(strict_types=1);
13
14
namespace Sylius\Bundle\ShopBundle\DependencyInjection;
15
16
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17
use Symfony\Component\Config\Definition\ConfigurationInterface;
18
19
final class Configuration implements ConfigurationInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function getConfigTreeBuilder(): TreeBuilder
25
    {
26
        $treeBuilder = new TreeBuilder('sylius_shop');
27
        $rootNode = $treeBuilder->getRootNode();
28
29
        $rootNode
30
            ->children()
31
                ->enumNode('locale_switcher')->values(['storage', 'url'])->defaultValue('url')->end()
32
                ->scalarNode('firewall_context_name')->defaultValue('shop')->end()
33
                ->arrayNode('checkout_resolver')
34
                    ->addDefaultsIfNotSet()
35
                    ->children()
36
                        ->booleanNode('enabled')
37
                            ->defaultTrue()
38
                        ->end()
39
                        ->scalarNode('pattern')
40
                            ->defaultValue('/checkout/.+')
41
                            ->validate()
42
                            ->ifTrue(
43
                                /** @param mixed $pattern */
44
                                function ($pattern) {
45
                                    return !is_string($pattern);
46
                                }
47
                            )
48
                                ->thenInvalid('Invalid pattern "%s"')
49
                            ->end()
50
                        ->end()
51
                        ->arrayNode('route_map')
52
                            ->useAttributeAsKey('name')
53
                            ->arrayPrototype()
54
                                ->children()
55
                                    ->scalarNode('route')
56
                                        ->cannotBeEmpty()
57
                                        ->isRequired()
58
                                    ->end()
59
                                ->end()
60
                            ->end()
61
                        ->end()
62
                    ->end()
63
                ->end()
64
                ->arrayNode('product_grid')
65
                    ->addDefaultsIfNotSet()
66
                    ->children()
67
                        ->booleanNode('include_all_descendants')
68
                            ->defaultFalse()
69
                        ->end()
70
                    ->end()
71
                ->end()
72
            ->end()
73
        ;
74
75
        return $treeBuilder;
76
    }
77
}
78