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

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 70
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 64 2
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