Passed
Push — master ( a15571...193ee3 )
by Damien
03:53
created

CustomConfigurationCompilerPass   A

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