ImporterCompilerPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCmsPlugin\DependencyInjection\Compiler;
12
13
use BitBag\SyliusCmsPlugin\Importer\ImporterInterface;
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
final class ImporterCompilerPass implements CompilerPassInterface
19
{
20
    private const TAG_ID = 'bitbag.cmsplugin.importer';
21
22
    public function process(ContainerBuilder $container): void
23
    {
24
        if (!$container->has('bitbag_sylius_cms_plugin.importer.chain')) {
25
            return;
26
        }
27
28
        $container
29
            ->registerForAutoconfiguration(ImporterInterface::class)
30
            ->addTag(self::TAG_ID)
31
        ;
32
33
        $taggedServices = $container->findTaggedServiceIds(self::TAG_ID);
34
        $definition = $container->findDefinition('bitbag_sylius_cms_plugin.importer.chain');
35
36
        foreach ($taggedServices as $id => $tags) {
37
            $definition->addMethodCall('addImporter', [new Reference($id)]);
38
        }
39
    }
40
}
41