Issues (6)

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;
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function getConfigTreeBuilder(): TreeBuilder
22
    {
23
        $treeBuilder = new TreeBuilder('koff_i18n_form');
24
        $rootNode = method_exists($treeBuilder, 'getRootNode')
25
            ? $treeBuilder->getRootNode()
26
            : $treeBuilder->root('koff_i18n_form');
0 ignored issues
show
The method root() does not exist on Symfony\Component\Config...ion\Builder\TreeBuilder. ( Ignorable by Annotation )

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

26
            : $treeBuilder->/** @scrutinizer ignore-call */ root('koff_i18n_form');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
28
        $this->convertStringToArray = function ($v) {
29
            return preg_split('/\s*[,|]\s*/', $v);
30
        };
31
32
        $this->localesSection($rootNode);
33
        $this->requiredLocalesSection($rootNode);
34
        $this->excludedFieldsSection($rootNode);
35
        $this->formThemeSection($rootNode);
36
37
        return $treeBuilder;
38
    }
39
40
    private function localesSection(ArrayNodeDefinition $rootNode)
41
    {
42
        $rootNode
43
            ->children()
44
                ->arrayNode('locales')
45
                    ->defaultValue(['en'])
46
                    ->requiresAtLeastOneElement()
47
                    ->scalarPrototype()->end()
48
                    ->beforeNormalization()->ifString()->then($this->convertStringToArray)->end()
0 ignored issues
show
The method beforeNormalization() 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...\Builder\NodeDefinition. ( Ignorable by Annotation )

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

48
                    ->/** @scrutinizer ignore-call */ beforeNormalization()->ifString()->then($this->convertStringToArray)->end()
Loading history...
49
                ->end()
50
        ;
51
    }
52
53
    private function requiredLocalesSection(ArrayNodeDefinition $rootNode)
54
    {
55
        $rootNode
56
            ->children()
57
                ->arrayNode('required_locales')
58
                    ->scalarPrototype()->end()
59
                    ->beforeNormalization()->ifString()->then($this->convertStringToArray)->end()
60
                ->end()
61
        ;
62
    }
63
64
    private function excludedFieldsSection(ArrayNodeDefinition $rootNode)
65
    {
66
        $rootNode
67
            ->children()
68
                ->arrayNode('excluded_fields')
69
                    ->defaultValue(['id', 'locale', 'translatable'])
70
                    ->scalarPrototype()->end()
71
                    ->beforeNormalization()->ifString()->then($this->convertStringToArray)->end()
72
                ->end()
73
        ;
74
    }
75
76
    private function formThemeSection(ArrayNodeDefinition $rootNode)
77
    {
78
        $rootNode
79
            ->children()
80
                ->scalarNode('form_theme')
81
                    ->validate()->ifNotInArray(['bootstrap_3', 'bootstrap_4'])->thenUnset()->end()
82
                ->end()
83
        ;
84
    }
85
}
86