Completed
Pull Request — 3.1 (#348)
by Piotr
07:35
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 61
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 58 4
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
class Configuration implements ConfigurationInterface
18
{
19
    public function getConfigTreeBuilder(): TreeBuilder
20
    {
21
        if (true === method_exists(TreeBuilder::class, 'getRootNode')) {
22
            $treeBuilder = new TreeBuilder('fsi_admin');
23
            $rootNode = $treeBuilder->getRootNode();
24
        } else {
25
            $treeBuilder = new TreeBuilder();
26
            $rootNode = $treeBuilder->root('fsi_admin');
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...
27
        }
28
29
        $rootNode
30
            ->validate()
31
                ->always(function($v) {
32
                    if (!isset($v['templates']['crud_list'])) {
33
                        $v['templates']['crud_list'] = $v['templates']['list'];
34
                    }
35
                    if (!isset($v['templates']['crud_form'])) {
36
                        $v['templates']['crud_form'] = $v['templates']['form'];
37
                    }
38
                    return $v;
39
                })
40
            ->end()
41
            ->children()
42
                ->scalarNode('default_locale')->defaultValue('%locale%')->end()
43
                ->arrayNode('locales')
44
                    ->prototype('scalar')->end()
45
                    ->defaultValue(['%locale%'])
46
                ->end()
47
                ->scalarNode('menu_config_path')->defaultValue("%kernel.root_dir%/config/admin_menu.yml")->end()
48
                ->arrayNode('templates')
49
                    ->addDefaultsIfNotSet()
50
                    ->children()
51
                        ->scalarNode('base')->defaultValue('@FSiAdmin/base.html.twig')->end()
52
                        ->scalarNode('index_page')->defaultValue('@FSiAdmin/Admin/index.html.twig')->end()
53
                        ->scalarNode('list')->defaultValue('@FSiAdmin/List/list.html.twig')->end()
54
                        ->scalarNode('form')->defaultValue('@FSiAdmin/Form/form.html.twig')->end()
55
                        ->scalarNode('crud_list')->defaultValue('@FSiAdmin/CRUD/list.html.twig')->end()
56
                        ->scalarNode('crud_form')->defaultNull()->end()
57
                        ->scalarNode('resource')->defaultValue('@FSiAdmin/Resource/resource.html.twig')->end()
58
                        ->scalarNode('display')->defaultValue('@FSiAdmin/Display/display.html.twig')->end()
59
                        ->scalarNode('datagrid_theme')->defaultValue('@FSiAdmin/CRUD/datagrid.html.twig')->end()
60
                        ->scalarNode('datasource_theme')->defaultValue('@FSiAdmin/CRUD/datasource.html.twig')->end()
61
                        ->scalarNode('form_theme')->defaultValue('@FSiAdmin/Form/form_theme.html.twig')->end()
62
                    ->end()
63
                ->end()
64
                ->arrayNode('annotations')
65
                    ->addDefaultsIfNotSet()
66
                    ->children()
67
                        ->arrayNode('dirs')
68
                            ->prototype('scalar')->defaultValue([])->end()
69
                        ->end()
70
                    ->end()
71
                ->end()
72
            ->end()
73
        ;
74
75
        return $treeBuilder;
76
    }
77
}
78