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

EventListener::processMethod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
crap 2
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