Completed
Pull Request — 5.1 (#2266)
by
unknown
12:07
created

MediaHandlerCompilerPass   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 40 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 14
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 14 27 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Kunstmaan\MediaBundle\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
 * MediaHandlerCompilerPass
11
 */
12
class MediaHandlerCompilerPass implements CompilerPassInterface
13
{
14
    /**
15
     * You can modify the container here before it is dumped to PHP code.
16
     *
17
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
18
     */
19
    public function process(ContainerBuilder $container)
20
    {
21
        if ($container->hasDefinition('kunstmaan_media.media_manager')) {
22
            $definition = $container->getDefinition('kunstmaan_media.media_manager');
23
24
            foreach ($container->findTaggedServiceIds('kunstmaan_media.media_handler') as $id => $attributes) {
25
                $definition->addMethodCall('addHandler', array(new Reference($id)));
26
            }
27
        }
28
29 View Code Duplication
        if ($container->hasDefinition('kunstmaan_media.icon_font_manager')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
30
            $definition = $container->getDefinition('kunstmaan_media.icon_font_manager');
31
32
            foreach ($container->findTaggedServiceIds('kunstmaan_media.icon_font.loader') as $id => $attributes) {
33
                $definition->addMethodCall('addLoader', array(new Reference($id), $id));
34
            }
35
        }
36
37
        // Inject the tagged resolvers into our cache manager override
38 View Code Duplication
        if ($container->hasDefinition('Kunstmaan\MediaBundle\Helper\Imagine\CacheManager')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
39
            $manager = $container->getDefinition('Kunstmaan\MediaBundle\Helper\Imagine\CacheManager');
40
41
            foreach ($container->findTaggedServiceIds('liip_imagine.cache.resolver') as $id => $tag) {
42
                $manager->addMethodCall('addResolver', [$tag[0]['resolver'], new Reference($id)]);
43
            }
44
        }
45
    }
46
}
47