Completed
Push — master ( b0979f...a5561b )
by Vladimir
03:29 queued 41s
created

Configuration::localesSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 1
eloc 13
nc 1
nop 1
1
<?php
2
3
namespace Koff\Bundle\I18nFormBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * Class Configuration.
11
 *
12
 * @author Sadicov Vladimir <[email protected]>
13
 */
14
class Configuration implements ConfigurationInterface
15
{
16
    private $convertStringToArray = null;
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function getConfigTreeBuilder()
21
    {
22
        $treeBuilder = new TreeBuilder();
23
        $rootNode = $treeBuilder->root('i18n_form');
24
25
        $this->convertStringToArray = function ($v) {
26
            return preg_split('/\s*[,|]\s*/', $v);
27
        };
28
29
        $this->localesSection($rootNode);
30
        $this->requiredLocalesSection($rootNode);
31
        $this->excludedFieldsSection($rootNode);
32
33
        return $treeBuilder;
34
    }
35
36
    /**
37
     * @param ArrayNodeDefinition $rootNode
38
     */
39 View Code Duplication
    private function localesSection(ArrayNodeDefinition $rootNode)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        $rootNode
42
            ->children()
43
                ->arrayNode('locales')
44
                    ->defaultValue(['en'])
45
                    ->beforeNormalization()
46
                        ->ifString()
47
                            ->then($this->convertStringToArray)
48
                        ->end()
49
                    ->end()
50
                    ->requiresAtLeastOneElement()
0 ignored issues
show
Bug introduced by
The method requiresAtLeastOneElement() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
                    ->/** @scrutinizer ignore-call */ requiresAtLeastOneElement()
Loading history...
51
                    ->prototype('scalar')
52
                ->end()
53
            ->end()
54
        ;
55
    }
56
57
    /**
58
     * @param ArrayNodeDefinition $rootNode
59
     */
60
    private function requiredLocalesSection(ArrayNodeDefinition $rootNode)
61
    {
62
        $rootNode
63
            ->children()
64
                ->arrayNode('required_locales')
65
                    ->beforeNormalization()
66
                        ->ifString()
67
                            ->then($this->convertStringToArray)
68
                        ->end()
69
                    ->end()
70
                    ->prototype('scalar')
0 ignored issues
show
Bug introduced by
The method prototype() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
                    ->/** @scrutinizer ignore-call */ prototype('scalar')
Loading history...
71
                ->end()
72
            ->end()
73
        ;
74
    }
75
76
    /**
77
     * @param ArrayNodeDefinition $rootNode
78
     */
79 View Code Duplication
    private function excludedFieldsSection(ArrayNodeDefinition $rootNode)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $rootNode
82
            ->children()
83
                ->arrayNode('locales')
84
                    ->defaultValue(['id', 'locale', 'translatable'])
85
                    ->beforeNormalization()
86
                        ->ifString()
87
                            ->then($this->convertStringToArray)
88
                        ->end()
89
                    ->end()
90
                    ->prototype('scalar')
91
                ->end()
92
            ->end()
93
        ;
94
    }
95
}
96