Passed
Push — 4.0-wip ( 6335ec...2b093e )
by Damien
04:23
created

AddProviderCompilerPass::process()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 15
rs 10
1
<?php
2
3
namespace DH\AuditorBundle\DependencyInjection\Compiler;
4
5
use DH\Auditor\Auditor;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class AddProviderCompilerPass implements CompilerPassInterface
11
{
12
    /**
13
     * Get all providers based on their tag (`dh_auditor.provider`) and register them.
14
     */
15
    public function process(ContainerBuilder $container): void
16
    {
17
        if (!$container->hasDefinition(Auditor::class)) {
18
            return;
19
        }
20
21
        $auditorDefinition = $container->getDefinition(Auditor::class);
22
23
        $providers = [];
24
        foreach ($container->findTaggedServiceIds('dh_auditor.provider') as $providerId => $attributes) {
25
            $providers[] = new Reference($providerId);
26
        }
27
28
        foreach ($providers as $provider) {
29
            $auditorDefinition->addMethodCall('registerProvider', [$provider]);
30
        }
31
    }
32
}
33