Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 37
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 30
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 37
rs 9.44
1
<?php
2
3
/*
4
 * This file is part of the ModularBundle project.
5
 *
6
 * (c) Anthonius Munthi <https://itstoni.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\Bundle\Modular\DependencyInjection;
15
16
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17
use Symfony\Component\Config\Definition\ConfigurationInterface;
18
19
class Configuration implements ConfigurationInterface
20
{
21
    /**
22
     * @psalm-suppress TooFew
23
     */
24
    public function getConfigTreeBuilder(): TreeBuilder
25
    {
26
        // @codeCoverageIgnoreStart
27
        if (method_exists(TreeBuilder::class, 'getRootNode')) {
28
            $treeBuilder = new TreeBuilder('doyo_modular_extension');
29
            $rootNode    = $treeBuilder->getRootNode();
30
        } else {
31
            $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

31
            $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...
32
            $rootNode    = $treeBuilder->root('doyo_modular_extension');
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

32
            /** @scrutinizer ignore-call */ 
33
            $rootNode    = $treeBuilder->root('doyo_modular_extension');

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...
33
        }
34
        // @codeCoverageIgnoreEnd
35
36
        $rootNode
37
            ->children()
38
                ->booleanNode('use_annotation')->defaultTrue()->end()
39
                ->scalarNode('module_root_dir')->defaultValue('src')->end()
40
                ->arrayNode('doctrine')
41
                    ->addDefaultsIfNotSet()
42
                    ->children()
43
                        ->booleanNode('use_orm')->defaultTrue()->end()
44
                        ->booleanNode('use_mongodb')->defaultFalse()->end()
45
                        ->scalarNode('entity_dir')->defaultValue('Entity')->end()
46
                        ->scalarNode('document_dir')->defaultValue('Document')->end()
47
                        ->scalarNode('mapping_dir')->defaultValue('Resources/doctrine')->end()
48
                    ->end()
49
                ->end()
50
                ->arrayNode('config_paths')
51
                    ->addDefaultsIfNotSet()
52
                    ->children()
53
                        ->scalarNode('api_platform')->defaultValue('Resources/api')->end()
54
                        ->scalarNode('validation')->defaultValue('Resources/validation')->end()
55
                        ->scalarNode('serialization')->defaultValue('Resources/serialization')->end()
56
                    ->end()
57
                ->end()
58
            ->end();
59
60
        return $treeBuilder;
61
    }
62
}
63