CustomConfigurationCompilerPass   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 9

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 35 9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DH\AuditorBundle\DependencyInjection\Compiler;
6
7
use DH\Auditor\Configuration;
8
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Reference;
11
12
/**
13
 * @see \DH\AuditorBundle\Tests\DependencyInjection\Compiler\CustomConfigurationCompilerPassTest
14
 */
15
class CustomConfigurationCompilerPass implements CompilerPassInterface
16
{
17
    public function process(ContainerBuilder $container): void
18
    {
19
        if (!$container->hasDefinition(Configuration::class)) {
20
            return;
21
        }
22
23
        if (!$container->hasParameter('dh_auditor.configuration')) {
24
            return;
25
        }
26
27
        $providerDefinition = $container->getDefinition(Configuration::class);
28
        $config = $container->getParameter('dh_auditor.configuration');
29
30
        // User provider service
31
        \assert(\is_array($config) && \array_key_exists('user_provider', $config));
32
        $serviceId = $config['user_provider'];
33
        if (null !== $serviceId) {
34
            $reference = new Reference($serviceId);
35
            $providerDefinition->addMethodCall('setUserProvider', [$reference]);
36
        }
37
38
        // Role checker service
39
        \assert(\is_array($config) && \array_key_exists('role_checker', $config));
40
        $serviceId = $config['role_checker'];
41
        if (null !== $serviceId) {
42
            $reference = new Reference($serviceId);
43
            $providerDefinition->addMethodCall('setRoleChecker', [$reference]);
44
        }
45
46
        // Security service
47
        \assert(\is_array($config) && \array_key_exists('security_provider', $config));
48
        $serviceId = $config['security_provider'];
49
        if (null !== $serviceId) {
50
            $reference = new Reference($serviceId);
51
            $providerDefinition->addMethodCall('setSecurityProvider', [$reference]);
52
        }
53
    }
54
}
55