Completed
Push — master ( 3f99c9...f99ebc )
by Quentin
8s
created

LoaderBridgeFormCompilerPass::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 18
loc 18
rs 9.2
cc 4
eloc 10
nc 4
nop 1
1
<?php
2
3
namespace Majora\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * Compiler pass to register bridge loaders into loader form bridge.
11
 */
12 View Code Duplication
class LoaderBridgeFormCompilerPass implements CompilerPassInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    /**
15
     * {@inheritdoc}
16
     *
17
     * Processes "majora.loader_bridge.form" tags
18
     */
19
    public function process(ContainerBuilder $container)
20
    {
21
        $entityCollectionType = $container->getDefinition('majora.loader.bridge.form.type.entity_collection');
22
        $loaders = $container->findTaggedServiceIds('majora.loader_bridge.form');
23
24
        foreach ($loaders as $loaderId => $tags) {
25
            foreach ($tags as $attributes) {
26
                if (!isset($attributes['alias'])) {
27
                    throw new \RuntimeException('Alias required for "majora.loader_bridge.form" tag.');
28
                }
29
30
                $entityCollectionType->addMethodCall(
31
                    'registerLoader',
32
                    [$attributes['alias'], new Reference($loaderId)]
33
                );
34
            }
35
        }
36
    }
37
}
38