Completed
Push — master ( 73caa0...72ac9c )
by Kévin
02:13
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 46
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 10
Bugs 2 Features 3
Metric Value
c 10
b 2
f 3
dl 0
loc 46
rs 8.9411
cc 3
eloc 38
nc 1
nop 0
1
<?php
2
3
/*
4
 * (c) Kévin Dunglas <[email protected]>
5
 *
6
 * This source file is subject to the MIT license that is bundled
7
 * with this source code in the file LICENSE.
8
 */
9
10
namespace Dunglas\ActionBundle\DependencyInjection;
11
12
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
13
use Symfony\Component\Config\Definition\ConfigurationInterface;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
17
/**
18
 * {@inheritdoc}
19
 *
20
 * @author Kévin Dunglas <[email protected]>
21
 */
22
class Configuration implements ConfigurationInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getConfigTreeBuilder()
28
    {
29
        $treeBuilder = new TreeBuilder();
30
        $treeBuilder->root('dunglas_action')
31
            ->fixXmlConfig('directory', 'directories')
32
            ->children()
33
                ->arrayNode('directories')
34
                    ->info('List of directories relative to the kernel root directory containing classes.')
35
                    ->useAttributeAsKey('prefix')
36
                    ->prototype('array')
37
                        ->prototype('scalar')->end()
38
                    ->end()
39
                    ->defaultValue([
40
                        'controller' => ['../src/*Bundle/Controller', '../src/*Bundle/Action'],
41
                        'command' => ['../src/*Bundle/Command'],
42
                        'event_subscriber' => ['../src/*Bundle/EventSubscriber'],
43
                    ])
44
                ->end()
45
                ->arrayNode('tags')
46
                    ->info('List of tags to add when implementing the corresponding class.')
47
                    ->useAttributeAsKey('class')
48
                    ->prototype('array')
49
                        // Converts 'console.command' to ['console.command']
1 ignored issue
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
                        ->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
51
                        ->prototype('array')
52
                            // Converts 'console.command' to ['console.command', []]
1 ignored issue
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53
                            ->beforeNormalization()->ifString()->then(function ($v) { return [$v, []]; })->end()
54
                            ->validate()
55
                                ->ifTrue(function ($v) {
56
                                    return count($v) !== 2 || !is_string($v[0]) || !is_array($v[1]);
57
                                })
58
                                ->thenInvalid('Invalid tag format. They must be as following: [\'my_tag.name\', [\'attribute\' => \'value\']]')
59
                            ->end()
60
                            ->prototype('variable')->end()
61
                        ->end()
62
                    ->end()
63
                    ->defaultValue([
64
                        Command::class => [['console.command', []]],
65
                        EventSubscriberInterface::class => [['kernel.event_subscriber', []]],
66
                    ])
67
                ->end()
68
            ->end()
69
        ->end();
70
71
        return $treeBuilder;
72
    }
73
}
74