RegisterSchemasPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 2 Features 1
Metric Value
c 5
b 2
f 1
dl 0
loc 18
rs 9.2
cc 4
eloc 9
nc 4
nop 1
1
<?php
2
3
namespace DoS\SettingsBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class RegisterSchemasPass implements CompilerPassInterface
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function process(ContainerBuilder $container)
15
    {
16
        if (!$container->hasDefinition('sylius.settings.schema_registry')) {
17
            return;
18
        }
19
20
        $schemaRegistry = $container->getDefinition('sylius.settings.schema_registry');
21
22
        foreach ($container->findTaggedServiceIds('dos.settings_schema') as $id => $attributes) {
23
            if (!array_key_exists('namespace', $attributes[0])) {
24
                throw new \InvalidArgumentException(sprintf('Service "%s" must define the "namespace" attribute on "sylius.settings_schema" tags.', $id));
25
            }
26
27
            $namespace = $attributes[0]['namespace'];
28
29
            $schemaRegistry->addMethodCall('registerSchema', array($namespace, new Reference($id)));
30
        }
31
    }
32
}
33