Passed
Pull Request — master (#39)
by Alexander
02:24 queued 01:07
created

DeferredDispatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 20
ccs 0
cts 8
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 4 1
A flush() 0 4 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\EventDispatcher\Dispatcher;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
9
final class DeferredDispatcher implements EventDispatcherInterface
10
{
11
    private EventDispatcherInterface $dispatcher;
12
    private array $events = [];
13
14
    public function __construct(EventDispatcherInterface $dispatcher)
15
    {
16
        $this->dispatcher = $dispatcher;
17
    }
18
19
    public function dispatch(object $event)
20
    {
21
        $this->events[] = $event;
22
        return $event;
23
    }
24
25
    public function flush(): void
26
    {
27
        foreach ($this->events as $event) {
28
            $this->dispatcher->dispatch($event);
29
        }
30
    }
31
}
32