Configuration   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 39
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 13 1
A messagesNode() 0 31 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enqueue\SimpleBus\Bridge\Symfony\Bundle\DependencyInjection;
6
7
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
use Symfony\Component\Config\Definition\ConfigurationInterface;
10
11
class Configuration implements ConfigurationInterface
12
{
13
    public const TYPE_COMMANDS = 'commands';
14
    public const TYPE_EVENTS = 'events';
15
16
    public function getConfigTreeBuilder(): TreeBuilder
17
    {
18
        $treeBuilder = new TreeBuilder('enqueue_simple_bus');
19
20
        $rootNode = $treeBuilder->getRootNode();
21
        $rootNode
22
            ->children()
23
                ->append($this->messagesNode(self::TYPE_COMMANDS))
24
                ->append($this->messagesNode(self::TYPE_EVENTS))
25
            ->end()
26
        ;
27
28
        return $treeBuilder;
29
    }
30
31
    private function messagesNode(string $type): ArrayNodeDefinition
32
    {
33
        return (new ArrayNodeDefinition($type))
34
            ->beforeNormalization()
35
                ->ifString()
36
                ->then(function (string $config): array {
37
                    return ['default_queue' => $config, 'enabled' => true];
38
                })
39
            ->end()
40
            ->canBeEnabled()
0 ignored issues
show
Bug introduced by
The method canBeEnabled() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

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

40
            ->/** @scrutinizer ignore-call */ canBeEnabled()
Loading history...
41
            ->children()
42
                ->scalarNode('transport_name')
43
                    ->cannotBeEmpty()
44
                    ->defaultValue('default')
45
                ->end()
46
                ->scalarNode('default_queue')
47
                    ->cannotBeEmpty()
48
                    ->defaultValue(sprintf('asynchronous_%s', $type))
49
                ->end()
50
                ->scalarNode('processor_service_id')
51
                    ->cannotBeEmpty()
52
                    ->defaultValue(sprintf('enqueue.simple_bus.%s_processor', $type))
53
                ->end()
54
                ->arrayNode('queue_map')
55
                    ->requiresAtLeastOneElement()
56
                    ->useAttributeAsKey(true)
57
                    ->scalarPrototype()
58
                        ->isRequired()
59
                    ->end()
60
                ->end()
61
            ->end()
62
        ;
63
    }
64
}
65