Completed
Push — master ( 6b9165...54453e )
by Peter
08:25 queued 08:22
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.054

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 9
cts 11
cp 0.8182
rs 9.456
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 3.054
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Bundle\PaginationBundle\DependencyInjection;
12
13
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
class Configuration implements ConfigurationInterface
18
{
19
    /**
20
     * @return TreeBuilder
21
     */
22 1
    public function getConfigTreeBuilder()
23
    {
24 1
        $tree_builder = new TreeBuilder('gpslab_pagination');
25
26 1
        if (method_exists($tree_builder, 'getRootNode')) {
27
            // Symfony 4.2 +
28
            $root = $tree_builder->getRootNode();
29
        } else {
30
            // Symfony 4.1 and below
31 1
            $root = $tree_builder->root('gpslab_pagination');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
32
        }
33
34
        // @codeCoverageIgnoreStart
35
        if (!$root instanceof ArrayNodeDefinition) {
36
            throw new \RuntimeException(sprintf(
37
                'Config root node must be a "%s", given "%s".',
38
                'Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition',
39
                get_class($root)
40
            ));
41
        }
42
        // @codeCoverageIgnoreEnd
43
44 1
        $root->addDefaultsIfNotSet();
45 1
        $root->children()->scalarNode('max_navigate')->defaultValue(5);
46 1
        $root->children()->scalarNode('parameter_name')->defaultValue('page');
47 1
        $root->children()->scalarNode('template')->defaultValue('GpsLabPaginationBundle::pagination.html.twig');
48
49 1
        return $tree_builder;
50
    }
51
}
52