RegisterSchemasPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 5
Bugs 2 Features 1
Metric Value
wmc 4
c 5
b 2
f 1
lcom 0
cbo 3
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 4
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