PheatureFlagsBundle::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 9
ccs 0
cts 6
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pheature\Community\Symfony;
6
7
use Pheature\Community\Symfony\DependencyInjection\FeatureFinderFactoryPass;
8
use Pheature\Community\Symfony\DependencyInjection\FeatureRepositoryFactoryPass;
9
use Pheature\Community\Symfony\DependencyInjection\SegmentFactoryPass;
10
use Pheature\Community\Symfony\DependencyInjection\ToggleStrategyFactoryPass;
11
use Pheature\Community\Symfony\DependencyInjection\ToggleAPIPass;
12
use Pheature\Model\Toggle\EnableByMatchingIdentityId;
13
use Pheature\Model\Toggle\EnableByMatchingSegment;
14
use Pheature\Model\Toggle\IdentitySegment;
15
use Pheature\Model\Toggle\SegmentFactory;
16
use Pheature\Model\Toggle\StrategyFactory;
17
use Pheature\Model\Toggle\StrictMatchingSegment;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\HttpKernel\Bundle\Bundle;
20
21
final class PheatureFlagsBundle extends Bundle
22
{
23
    private const DEFAULT_CONFIG = [
24
        'driver' => 'inmemory',
25
        'api_prefix' => '',
26
        'api_enabled' => false,
27
        'segment_types' => [
28
            [
29
                'type' => IdentitySegment::NAME,
30
                'factory_id' => SegmentFactory::class
31
            ],
32
            [
33
                'type' => StrictMatchingSegment::NAME,
34
                'factory_id' => SegmentFactory::class
35
            ]
36
        ],
37
        'strategy_types' => [
38
            [
39
                'type' => EnableByMatchingSegment::NAME,
40
                'factory_id' => StrategyFactory::class
41
            ],
42
            [
43
                'type' => EnableByMatchingIdentityId::NAME,
44
                'factory_id' => StrategyFactory::class
45
            ]
46
        ],
47
        'toggles' => [],
48
    ];
49
50
    public function build(ContainerBuilder $container): void
51
    {
52
        $container->loadFromExtension('pheature_flags', self::DEFAULT_CONFIG);
53
54
        $container->addCompilerPass(new SegmentFactoryPass());
55
        $container->addCompilerPass(new ToggleStrategyFactoryPass());
56
        $container->addCompilerPass(new FeatureRepositoryFactoryPass());
57
        $container->addCompilerPass(new FeatureFinderFactoryPass());
58
        $container->addCompilerPass(new ToggleAPIPass());
59
    }
60
}
61