Passed
Push — master ( 83ac3f...15f95c )
by Alexander
11:33 queued 10:26
created

CompositeDispatcher   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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