MediaProviderPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 25 5
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 Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Reference;
16
17
final class MediaProviderPass implements CompilerPassInterface
18
{
19
    public function process(ContainerBuilder $container): void
20
    {
21
        if (!$container->hasDefinition('bitbag_sylius_cms_plugin.registry.media_provider')) {
22
            return;
23
        }
24
25
        $providerRegistry = $container->getDefinition('bitbag_sylius_cms_plugin.registry.media_provider');
26
        $providers = [];
27
28
        foreach ($container->findTaggedServiceIds('bitbag_sylius_cms_plugin.media_provider') as $id => $attributes) {
29
            if (!isset($attributes[0]['type']) || !isset($attributes[0]['label'])) {
30
                throw new \InvalidArgumentException('Tagged media provider needs to have `type` and `label` attribute.');
31
            }
32
33
            $name = $attributes[0]['label'];
34
            $type = $attributes[0]['type'];
35
36
            $providers[$name] = $type;
37
38
            $providerRegistry->addMethodCall('register', [$type, new Reference($id)]);
39
        }
40
41
        ksort($providers);
42
43
        $container->setParameter('bitbag_sylius_cms_plugin.media_providers', $providers);
44
    }
45
}
46