TaggedEnumCollectorCompilerPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yokai\EnumBundle\DependencyInjection\CompilerPass;
6
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
/**
12
 * @author Yann Eugoné <[email protected]>
13
 */
14
class TaggedEnumCollectorCompilerPass implements CompilerPassInterface
15
{
16
    /**
17
     * @inheritdoc
18
     */
19
    public function process(ContainerBuilder $container): void
20
    {
21
        if (!$container->hasDefinition('enum.registry')) {
22
            return;
23
        }
24
25
        $registry = $container->getDefinition('enum.registry');
26
27
        foreach (array_keys($container->findTaggedServiceIds('enum')) as $enum) {
28
            $registry->addMethodCall('add', [new Reference($enum)]);
29
        }
30
    }
31
}
32