Completed
Pull Request — 2.x (#361)
by Christian
01:12
created

Configuration::addHttpClientSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\ArrayNodeDefinition;
17
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
18
use Symfony\Component\Config\Definition\ConfigurationInterface;
19
20
/**
21
 * This is the class that validates and merges configuration from your app/config files.
22
 */
23
class Configuration implements ConfigurationInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getConfigTreeBuilder()
29
    {
30
        $treeBuilder = new TreeBuilder('sonata_seo');
31
32
        // Keep compatibility with symfony/config < 4.2
33
        if (!method_exists($treeBuilder, 'getRootNode')) {
34
            $rootNode = $treeBuilder->root('sonata_seo');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
35
        } else {
36
            $rootNode = $treeBuilder->getRootNode();
37
        }
38
39
        $rootNode
40
            ->children()
41
                ->scalarNode('encoding')->defaultValue('UTF-8')->end()
42
                ->arrayNode('page')
43
                    ->addDefaultsIfNotSet()
44
                    ->children()
45
                        ->scalarNode('default')->defaultValue('sonata.seo.page.default')->end()
46
                        ->arrayNode('head')
47
                            ->normalizeKeys(false)
48
                            ->useAttributeAsKey('attribute')
49
                            ->prototype('scalar')->end()
50
                        ->end()
51
                        ->arrayNode('metas')
52
                            ->normalizeKeys(false)
53
                            ->useAttributeAsKey('element')
54
                            ->prototype('array')
55
                                ->normalizeKeys(false)
56
                                ->useAttributeAsKey('name')
57
                                ->prototype('scalar')->end()
58
                            ->end()
59
                        ->end()
60
                        ->scalarNode('separator')->defaultValue(' - ')->end()
61
                        // NEXT_MAJOR: Make this field required
62
                        ->scalarNode('title')->defaultValue('Project name')->end()
63
                    ->end()
64
                ->end()
65
                ->arrayNode('sitemap')
66
                    ->addDefaultsIfNotSet()
67
                    ->children()
68
                        ->arrayNode('doctrine_orm')
69
                            ->prototype('variable')->end()
70
                        ->end()
71
                        ->arrayNode('services')
72
                            ->prototype('variable')->end()
73
                        ->end()
74
                    ->end()
75
                ->end()
76
            ->end()
77
        ;
78
79
        $this->addHttpClientSection($rootNode);
0 ignored issues
show
Compatibility introduced by
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition>. It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
80
81
        return $treeBuilder;
82
    }
83
84
    private function addHttpClientSection(ArrayNodeDefinition $node): void
85
    {
86
        $node
87
            ->children()
88
                ->arrayNode('http')
89
                    ->addDefaultsIfNotSet()
90
                    ->children()
91
                        ->scalarNode('client')
92
                            ->defaultNull()
93
                            ->info('Alias of the http client.')
94
                        ->end()
95
                        ->scalarNode('message_factory')
96
                            ->defaultNull()
97
                            ->info('Alias of the message factory.')
98
                        ->end()
99
                    ->end()
100
                ->end()
101
            ->end();
102
    }
103
}
104