ResolveAdapterDefinitionPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.0123

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 17
ccs 8
cts 9
cp 0.8889
rs 9.9
cc 3
nc 3
nop 1
crap 3.0123
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Artprima\PrometheusMetricsBundle\DependencyInjection\Compiler;
6
7
use Prometheus\Storage\APC;
8
use Prometheus\Storage\InMemory;
9
use Prometheus\Storage\Redis;
10
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
13
/**
14
 * ResolveAdapterDefinitionPass is a compilation pass that sets the metrics backend storage adapter.
15
 */
16
class ResolveAdapterDefinitionPass implements CompilerPassInterface
17
{
18 6
    public function process(ContainerBuilder $container)
19
    {
20 6
        if (!$container->hasDefinition('prometheus_metrics_bundle.adapter')) {
21
            return;
22
        }
23
24
        $adapterClasses = [
25 6
            'in_memory' => InMemory::class,
26
            'apcu' => APC::class,
27
            'redis' => Redis::class,
28
        ];
29
30 6
        $definition = $container->getDefinition('prometheus_metrics_bundle.adapter');
31 6
        $definition->setAbstract(false);
32 6
        $definition->setClass($adapterClasses[$container->getParameter('prometheus_metrics_bundle.type')]);
33 6
        if ('redis' === $container->getParameter('prometheus_metrics_bundle.type')) {
34 3
            $definition->setArguments([$container->getParameter('prometheus_metrics_bundle.redis')]);
35
        }
36 6
    }
37
}
38