Completed
Pull Request — 2.x (#327)
by
unknown
01:23
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 8.7853
c 0
b 0
f 0
cc 2
nc 2
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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\SeoBundle\DependencyInjection;
15
16
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17
use Symfony\Component\Config\Definition\ConfigurationInterface;
18
19
/**
20
 * This is the class that validates and merges configuration from your app/config files.
21
 */
22
class Configuration implements ConfigurationInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getConfigTreeBuilder()
28
    {
29
        $treeBuilder = new TreeBuilder('sonata_seo');
30
31
        // Keep compatibility with symfony/config < 4.2
32
        if (!method_exists($treeBuilder, 'getRootNode')) {
33
            $rootNode = $treeBuilder->root('sonata_seo');
34
        } else {
35
            $rootNode = $treeBuilder->getRootNode();
36
        }
37
38
        $rootNode
39
            ->children()
40
                ->scalarNode('encoding')->defaultValue('UTF-8')->end()
41
                ->arrayNode('page')
42
                    ->addDefaultsIfNotSet()
43
                    ->children()
44
                        ->scalarNode('default')->defaultValue('sonata.seo.page.default')->end()
45
                        ->arrayNode('head')
46
                            ->normalizeKeys(false)
47
                            ->useAttributeAsKey('attribute')
48
                            ->prototype('scalar')->end()
49
                        ->end()
50
                        ->arrayNode('metas')
51
                            ->normalizeKeys(false)
52
                            ->useAttributeAsKey('element')
53
                            ->prototype('array')
54
                                ->normalizeKeys(false)
55
                                ->useAttributeAsKey('name')
56
                                ->prototype('scalar')->end()
57
                            ->end()
58
                        ->end()
59
                        ->scalarNode('separator')->defaultValue(' - ')->end()
60
                        // NEXT_MAJOR: Make this field required
61
                        ->arrayNode('title')
62
                            ->beforeNormalization()
63
                                ->ifString()
64
                                ->then(function ($v) {return ['suffix' => $v]; })
65
                            ->end()
66
                            ->addDefaultsIfNotSet()
67
                            ->treatNullLike(['suffix' => ''])
68
                            ->children()
69
                                ->scalarNode('prefix')->defaultValue('')->treatNullLike('')->end()
70
                                ->scalarNode('suffix')->defaultValue('Project name')->treatNullLike('')->end()
71
                            ->end()
72
                        ->end()
73
                    ->end()
74
                ->end()
75
                ->arrayNode('sitemap')
76
                    ->addDefaultsIfNotSet()
77
                    ->children()
78
                        ->arrayNode('doctrine_orm')
79
                            ->prototype('variable')->end()
80
                        ->end()
81
                        ->arrayNode('services')
82
                            ->prototype('variable')->end()
83
                        ->end()
84
                    ->end()
85
                ->end()
86
            ->end()
87
        ;
88
89
        return $treeBuilder;
90
    }
91
}
92