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

Dispatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 4
c 3
b 1
f 1
lcom 1
cbo 2
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A dispatch() 0 7 1
A resolveEventName() 0 7 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
}