Dispatcher   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 45
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A dispatch() 0 9 2
A resolveEventName() 0 8 1
A getClassname() 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 GBProd\DomainEvent\EventProvider;
8
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9
10
/**
11
 * Domain dispatcher implementation for symfony dispatcher
12
 * 
13
 * @author gbprod <[email protected]>
14
 */
15
class Dispatcher implements DomainEventDispatcher
16
{
17
    /**
18
     * @var EventDispatcherInterface
19
     */
20
    private $dispatcher;
21
    
22
    /**
23
     * @param EventDispatcherInterface $dispatcher
24
     */
25 3
    public function __construct(EventDispatcherInterface $dispatcher)
26
    {
27 3
        $this->dispatcher = $dispatcher;
28 3
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function dispatch(EventProvider $provider)
34
    {
35 1
        foreach ($provider->popEvents() as $event) {
36 1
            $this->dispatcher->dispatch(
37 1
                $this->resolveEventName($provider, $event),
38 1
                new Event($event)
39 1
            );
40 1
        }
41 1
    }
42
    
43 1
    private function resolveEventName(EventProvider $provider, DomainEvent $event)
44
    {
45 1
        return sprintf(
46 1
            '%s.%s',
47 1
            $this->getClassname($provider),
48 1
            $this->getClassname($event)
49 1
        );
50
    }
51
    
52 1
    private function getClassname($object)
53
    {
54 1
        $name = get_class($object);
55 1
        $pos = strrpos($name, '\\');
56
57 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...
58
    }
59
}