AddProviderCompilerPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DH\AuditorBundle\DependencyInjection\Compiler;
6
7
use DH\Auditor\Auditor;
8
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Reference;
11
12
class AddProviderCompilerPass implements CompilerPassInterface
13
{
14
    /**
15
     * Get all providers based on their tag (`dh_auditor.provider`) and register them.
16
     */
17
    public function process(ContainerBuilder $container): void
18
    {
19
        if (!$container->hasDefinition(Auditor::class)) {
20
            return;
21
        }
22
23
        $auditorDefinition = $container->getDefinition(Auditor::class);
24
25
        $providers = [];
26
        foreach (array_keys($container->findTaggedServiceIds('dh_auditor.provider')) as $providerId) {
27
            $providers[] = new Reference($providerId);
28
        }
29
30
        foreach ($providers as $provider) {
31
            $auditorDefinition->addMethodCall('registerProvider', [$provider]);
32
        }
33
    }
34
}
35