Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 86

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 86
rs 8.3054
c 0
b 0
f 0
cc 2
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
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\TranslationBundle\DependencyInjection;
15
16
use Sonata\TranslationBundle\Enum\TranslationFilterMode;
17
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
18
use Symfony\Component\Config\Definition\ConfigurationInterface;
19
20
/**
21
 * @author Nicolas Bastien <[email protected]>
22
 */
23
class Configuration implements ConfigurationInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getConfigTreeBuilder()
29
    {
30
        $treeBuilder = new TreeBuilder('sonata_translation');
31
32
        $rootNode = $treeBuilder->getRootNode();
33
34
        $rootNode
35
            ->children()
36
                ->arrayNode('locales')
37
                    ->info('The list of your frontend locales in which your models will be translatable.')
38
                    ->requiresAtLeastOneElement()
39
                    ->prototype('scalar')->end()
40
                ->end()
41
                ->scalarNode('default_locale')
42
                    ->defaultValue('en')
43
                    ->info('The frontend locale that is used by default.')
44
                ->end()
45
                ->enumNode('default_filter_mode')
46
                    ->values(TranslationFilterMode::AVAILABLE_FILTER_TYPES)
47
                    ->defaultValue(TranslationFilterMode::GEDMO)
48
                    ->info('The filter mode that is used by default.')
49
                ->end()
50
                ->arrayNode('gedmo')
51
                    ->canBeEnabled()
52
                    ->children()
53
                        ->arrayNode('implements')
54
                            ->requiresAtLeastOneElement()
55
                            ->prototype('scalar')->end()
56
                        ->end()
57
                        ->arrayNode('instanceof')
58
                            ->requiresAtLeastOneElement()
59
                            ->prototype('scalar')->end()
60
                        ->end()
61
                    ->end()
62
                ->end()
63
                ->arrayNode('knplabs')
64
                    ->canBeEnabled()
65
                    ->children()
66
                        ->arrayNode('implements')
67
                            ->requiresAtLeastOneElement()
68
                            ->prototype('scalar')->end()
69
                        ->end()
70
                        ->arrayNode('instanceof')
71
                            ->requiresAtLeastOneElement()
72
                            ->prototype('scalar')->end()
73
                        ->end()
74
                    ->end()
75
                ->end()
76
                ->arrayNode('phpcr')
77
                    ->canBeEnabled()
78
                    ->children()
79
                        ->arrayNode('implements')
80
                            ->requiresAtLeastOneElement()
81
                            ->prototype('scalar')->end()
82
                        ->end()
83
                        ->arrayNode('instanceof')
84
                            ->requiresAtLeastOneElement()
85
                            ->prototype('scalar')->end()
86
                        ->end()
87
                    ->end()
88
                ->end()
89
                ->booleanNode('locale_switcher')
90
                    ->info('Enable the global locale switcher services.')
91
                    ->defaultFalse()
92
                ->end()
93
                // NEXT_MAJOR: Fix locale to country flag mapping OR remove country flags entirely
94
                ->booleanNode('locale_switcher_show_country_flags')
95
                    ->info('Whether the language switcher should show languages as flags')
96
                    ->defaultTrue()
97
                ->end()
98
            ->end()
99
            ->beforeNormalization()
100
                ->ifTrue(static function ($v) {return !isset($v['locale_switcher_show_country_flags']) || true === $v['locale_switcher_show_country_flags']; })
101
                ->then(static function ($v) {
102
                    @trigger_error(sprintf(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
103
                        'Showing the country flags is deprecated. The flags will be removed in the next major version. Please set "%s" to false to avoid this message.',
104
                        'sonata_translation.locale_switcher_show_country_flags'
105
                    ), E_USER_DEPRECATED);
106
                    $v['locale_switcher_show_country_flags'] = $v['locale_switcher_show_country_flags'] ?? true;
107
108
                    return $v;
109
                })
110
            ->end();
111
112
        return $treeBuilder;
113
    }
114
}
115