LoaderBridgeFormCompilerPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 6.9849

Importance

Changes 0
Metric Value
dl 18
loc 18
ccs 6
cts 14
cp 0.4286
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 4
nop 1
crap 6.9849
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 2
    public function process(ContainerBuilder $container)
20
    {
21 2
        $entityCollectionType = $container->getDefinition('majora.loader.bridge.form.type.entity_collection');
22 2
        $loaders = $container->findTaggedServiceIds('majora.loader_bridge.form');
23
24 2
        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 1
        }
36 2
    }
37
}
38