AbstractSource   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 10 2
A addConfiguration() 0 18 1
createDefinition() 0 1 ?
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Bundle\JoseFramework\DependencyInjection\Source;
15
16
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Definition;
19
20
abstract class AbstractSource
21
{
22
    public function create(ContainerBuilder $container, string $type, string $name, array $config): void
23
    {
24
        $service_id = sprintf('jose.%s.%s', $type, $name);
25
        $definition = $this->createDefinition($container, $config);
26
        $definition->setPublic($config['is_public']);
27
        foreach ($config['tags'] as $id => $attributes) {
28
            $definition->addTag($id, $attributes);
29
        }
30
        $container->setDefinition($service_id, $definition);
31
    }
32
33
    public function addConfiguration(NodeDefinition $node): void
34
    {
35
        $node
36
            ->children()
37
            ->booleanNode('is_public')
38
            ->info('If true, the service will be public, else private.')
39
            ->defaultTrue()
40
            ->end()
41
            ->arrayNode('tags')
42
            ->info('A list of tags to be associated to the service.')
43
            ->useAttributeAsKey('name')
44
            ->treatNullLike([])
45
            ->treatFalseLike([])
46
            ->variablePrototype()->end()
47
            ->end()
48
            ->end()
49
        ;
50
    }
51
52
    abstract protected function createDefinition(ContainerBuilder $container, array $config): Definition;
53
}
54