Completed
Push — master ( a5561b...7e106d )
by Vladimir
02:28
created

src/DependencyInjection/Configuration.php (2 issues)

Labels
Severity
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
    /**
19
     * {@inheritdoc}
20
     */
21
    public function getConfigTreeBuilder()
22
    {
23
        $treeBuilder = new TreeBuilder();
24
        $rootNode = $treeBuilder->root('i18n_form');
25
26
        $this->convertStringToArray = function ($v) {
27
            return preg_split('/\s*[,|]\s*/', $v);
28
        };
29
30
        $this->localesSection($rootNode);
31
        $this->requiredLocalesSection($rootNode);
32
        $this->excludedFieldsSection($rootNode);
33
34
        return $treeBuilder;
35
    }
36
37
    /**
38
     * @param ArrayNodeDefinition $rootNode
39
     */
40
    private function localesSection(ArrayNodeDefinition $rootNode)
41
    {
42
        $rootNode
43
            ->children()
44
                ->arrayNode('locales')
45
                    ->defaultValue(['en'])
46
                    ->beforeNormalization()
47
                        ->ifString()->then($this->convertStringToArray)
48
                    ->end()
49
                    ->requiresAtLeastOneElement()
0 ignored issues
show
The method requiresAtLeastOneElement() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition 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

49
                    ->/** @scrutinizer ignore-call */ requiresAtLeastOneElement()
Loading history...
50
                    ->prototype('scalar')
51
                ->end()
52
            ->end()
53
        ;
54
    }
55
56
    /**
57
     * @param ArrayNodeDefinition $rootNode
58
     */
59
    private function requiredLocalesSection(ArrayNodeDefinition $rootNode)
60
    {
61
        $rootNode
62
            ->children()
63
                ->arrayNode('required_locales')
64
                    ->beforeNormalization()
65
                        ->ifString()->then($this->convertStringToArray)
66
                    ->end()
67
                    ->prototype('scalar')
0 ignored issues
show
The method prototype() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition 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

67
                    ->/** @scrutinizer ignore-call */ prototype('scalar')
Loading history...
68
                ->end()
69
            ->end()
70
        ;
71
    }
72
73
    /**
74
     * @param ArrayNodeDefinition $rootNode
75
     */
76
    private function excludedFieldsSection(ArrayNodeDefinition $rootNode)
77
    {
78
        $rootNode
79
            ->children()
80
                ->arrayNode('locales')
81
                    ->defaultValue(['id', 'locale', 'translatable'])
82
                    ->beforeNormalization()
83
                        ->ifString()->then($this->convertStringToArray)
84
                    ->end()
85
                    ->prototype('scalar')
86
                ->end()
87
            ->end()
88
        ;
89
    }
90
}
91