Configuration   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 3
c 6
b 1
f 0
lcom 0
cbo 3
dl 0
loc 61
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 55 3
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('methods')
34
                    ->info('The list of methods to autowire.')
35
                    ->prototype('scalar')->end()
36
                    ->defaultValue(['__construct', 'get*', 'set*'])
37
                ->end()
38
                ->arrayNode('directories')
39
                    ->info('List of directories relative to the kernel root directory containing classes.')
40
                    ->prototype('scalar')->end()
41
                    ->defaultValue([
42
                        '../src/*Bundle/Action',
43
                        '../src/*Bundle/Command',
44
                        '../src/*Bundle/Controller',
45
                        '../src/*Bundle/EventSubscriber',
46
                        '../src/*Bundle/Twig',
47
                    ])
48
                ->end()
49
                ->arrayNode('tags')
50
                    ->info('List of tags to add when implementing the corresponding class.')
51
                    ->useAttributeAsKey('class')
52
                    ->prototype('array')
53
                        // Converts 'console.command' to ['console.command']
54
                        ->beforeNormalization()->ifString()->then(function ($v) {
55
                            return [$v];
56
                        })->end()
57
                        ->prototype('array')
58
                            // Converts 'console.command' to ['console.command', []]
59
                            ->beforeNormalization()->ifString()->then(function ($v) {
60
                                return [$v, []];
61
                            })->end()
62
                            ->validate()
63
                                ->ifTrue(function ($v) {
64
                                    return count($v) !== 2 || !is_string($v[0]) || !is_array($v[1]);
65
                                })
66
                                ->thenInvalid('Invalid tag format. They must be as following: [\'my_tag.name\', [\'attribute\' => \'value\']]')
67
                            ->end()
68
                            ->prototype('variable')->end()
69
                        ->end()
70
                    ->end()
71
                    ->defaultValue([
72
                        Command::class => [['console.command', []]],
73
                        EventSubscriberInterface::class => [['kernel.event_subscriber', []]],
74
                        \Twig_ExtensionInterface::class => [['twig.extension', []]],
75
                    ])
76
                ->end()
77
            ->end()
78
        ->end();
79
80
        return $treeBuilder;
81
    }
82
}
83