Completed
Pull Request — master (#169)
by Mikołaj
02:27
created

ImporterCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\DependencyInjection\Compiler;
14
15
use BitBag\SyliusCmsPlugin\Importer\ImporterInterface;
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
final class ImporterCompilerPass implements CompilerPassInterface
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('bitbag.importer')
31
        ;
32
33
        $taggedServices = $container->findTaggedServiceIds('bitbag.importer');
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