Completed
Push — master ( 0fc7e8...41c904 )
by GBProd
04:06 queued 01:49
created

Dispatcher::resolveEventName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace GBProd\DomainEventBundle\Event;
4
5
use GBProd\DomainEvent\Dispatcher as DomainEventDispatcher;
6
use GBProd\DomainEvent\DomainEvent;
7
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
8
9
/**
10
 * Domain dispatcher implementation for symfony dispatcher
11
 * 
12
 * @author gbprod <[email protected]>
13
 */
14
class Dispatcher implements DomainEventDispatcher
15
{
16
    /**
17
     * @var EventDispatcherInterface
18
     */
19
    private $dispatcher;
20
    
21
    /**
22
     * @param EventDispatcherInterface $dispatcher
23
     */
24 3
    public function __construct(EventDispatcherInterface $dispatcher)
25 1
    {
26 3
        $this->dispatcher = $dispatcher;
27 3
    }
28
    
29
    /**
30
     * {@inheritdoc}
31
     */
32 1
    public function dispatch(DomainEvent $event)
33
    {
34 1
        $this->dispatcher->dispatch(
35 1
            $this->resolveEventName($event),
36 1
            new Event($event)
37 1
        );
38 1
    }
39
    
40 1
    private function resolveEventName(DomainEvent $event)
41
    {
42 1
        $name = get_class($event);
43 1
        $pos = strrpos($name, '\\');
44
45 1
        return $this->name = false === $pos ? $name : substr($name, $pos + 1);
0 ignored issues
show
Bug introduced by
The property name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
46
    }
47
}