Completed
Push — ezp-30616 ( 9239a0...7bf8e8 )
by
unknown
57:53 queued 37:56
created

SignalSlotPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 20
loc 20
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 17 17 5

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
/**
4
 * File containing the SignalSlotPass class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
10
11
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use LogicException;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
/**
17
 * This compiler pass will register slots in SignalDispatcher.
18
 */
19 View Code Duplication
class SignalSlotPass 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...
20
{
21
    public function process(ContainerBuilder $container)
22
    {
23
        if (!$container->hasDefinition('ezpublish.signalslot.signal_dispatcher')) {
24
            return;
25
        }
26
27
        $signalDispatcherDef = $container->getDefinition('ezpublish.signalslot.signal_dispatcher');
28
        foreach ($container->findTaggedServiceIds('ezpublish.api.slot') as $id => $attributes) {
29
            foreach ($attributes as $attribute) {
30
                if (!isset($attribute['signal'])) {
31
                    throw new LogicException("Could not find 'signal' attribute on '$id' service, which is mandatory for services tagged as 'ezpublish.api.slot'");
32
                }
33
34
                $signalDispatcherDef->addMethodCall('attach', array($attribute['signal'], new Reference($id)));
35
            }
36
        }
37
    }
38
}
39