Completed
Push — master ( 8151ca...23d5f0 )
by Kamil
17:17 queued 14s
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

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