ResolveAdapterDefinitionPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 19
ccs 8
cts 9
cp 0.8889
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 17 3
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