Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 22
nc 2
nop 0
dl 0
loc 27
rs 9.568
c 0
b 0
f 0
1
<?php
2
3
4
namespace Pfilsx\DataGrid\DependencyInjection;
5
6
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
10
class Configuration implements ConfigurationInterface
11
12
{
13
14
    /**
15
     * Generates the configuration tree builder.
16
     *
17
     * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
18
     */
19
    public function getConfigTreeBuilder()
20
    {
21
        if (\method_exists(TreeBuilder::class, 'getRootNode')) {
22
            $treeBuilder = new TreeBuilder('data_grid');
23
            $rootNode = $treeBuilder->getRootNode();
24
        } else {
25
            // BC layer for symfony/config 4.1 and older
26
            $treeBuilder = new TreeBuilder();
0 ignored issues
show
Bug introduced by
The call to Symfony\Component\Config...eBuilder::__construct() has too few arguments starting with name. ( 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 */ new TreeBuilder();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
27
            $rootNode = $treeBuilder->root('data_grid');
0 ignored issues
show
Bug introduced by
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

27
            /** @scrutinizer ignore-call */ 
28
            $rootNode = $treeBuilder->root('data_grid');

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...
28
        }
29
        $rootNode
30
            ->children()
31
                ->arrayNode('instances')
32
                    ->normalizeKeys(false)
33
                    ->useAttributeAsKey('name')
34
                    ->arrayPrototype()
35
                        ->children()
36
                            ->scalarNode('template')->defaultValue('@DataGrid/grid.blocks.html.twig')->end()
37
                            ->scalarNode('no_data_message')->defaultValue('No data found')->end()
38
                            ->booleanNode('pagination_enabled')->defaultValue(true)->end()
39
                            ->integerNode('pagination_limit')->defaultValue(10)->end()
40
                            ->scalarNode('translation_domain')->defaultNull()->end()
41
                        ->end()
42
                ->end()
43
            ->end();
44
45
        return $treeBuilder;
46
    }
47
}
48