Completed
Push — master ( b500ce...e6928b )
by Matze
03:15
created

EventListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 34.21 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 13
loc 38
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 13 13 1
A processMethod() 0 14 2

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 BrainExe\Core\Annotations\Builder;
4
5
use BrainExe\Annotations\Builder\ServiceDefinition;
6
use BrainExe\Core\Annotations\Listen;
7
use BrainExe\Core\DependencyInjection\CompilerPass\EventListenerCompilerPass;
8
use Doctrine\Common\Annotations\Annotation;
9
use ReflectionClass;
10
use ReflectionMethod;
11
use Symfony\Component\DependencyInjection\Definition;
12
13
class EventListener extends ServiceDefinition
14
{
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 2 View Code Duplication
    public function build(ReflectionClass $reflectionClass, Annotation $annotation)
0 ignored issues
show
Duplication introduced by
This method 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
        /** @var Definition $definition */
22 2
        list($serviceId, $definition) = parent::build($reflectionClass, $annotation);
23
24 2
        $serviceId = sprintf('__Listener.%s', $serviceId);
25
26 2
        $definition->addTag(EventListenerCompilerPass::TAG);
27 2
        $definition->setShared(false);
28 2
        $definition->setPublic(true);
29
30 2
        return [$serviceId, $definition];
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 2
    public function processMethod(Definition $definition, ReflectionMethod $method)
37
    {
38 2
        parent::processMethod($definition, $method);
39
40
        /** @var Listen $annotation */
41 2
        $annotation = $this->reader->getMethodAnnotation($method, Listen::class);
42 2
        if ($annotation) {
43 2
            $definition->addTag(EventListenerCompilerPass::TAG_METHOD, [
44 2
                'method' => $method->getName(),
45 2
                'event' => $annotation->event,
46 2
                'priority' => $annotation->priority,
47
            ]);
48
        }
49 2
    }
50
}
51