Completed
Pull Request — master (#20)
by Peter
02:11
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 10
cts 12
cp 0.8333
rs 9.552
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 3.0416
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 1
            $root = $tree_builder->getRootNode();
29
        } else {
30
            // Symfony 4.1 and below
31
            $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 1
        if (!$root instanceof ArrayNodeDefinition) {
35
            throw new \RuntimeException(sprintf('Config root node must be a "Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition", given "%s".', get_class($root)));
36
        }
37
38 1
        $root->addDefaultsIfNotSet();
39 1
        $root->children()->scalarNode('max_navigate')->defaultValue(5);
40 1
        $root->children()->scalarNode('parameter_name')->defaultValue('page');
41 1
        $root->children()->scalarNode('template')->defaultValue('GpsLabPaginationBundle::pagination.html.twig');
42
43 1
        return $tree_builder;
44
    }
45
}
46