Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 57
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 48
c 0
b 0
f 0
dl 0
loc 57
rs 9.1344
cc 4
nc 2
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

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

26
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('fsi_admin');

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

The explanatory message should give you some clue as to whether and when the function will be removed and what other function 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