CompositeDispatcher   A
last analyzed

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
declare(strict_types=1);
4
5
namespace Yiisoft\EventDispatcher\Dispatcher;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use Psr\EventDispatcher\StoppableEventInterface;
9
10
/**
11
 * Delegates dispatching an event to one or more dispatchers.
12
 */
13
final class CompositeDispatcher implements EventDispatcherInterface
14
{
15
    /**
16
     * @var EventDispatcherInterface[]
17
     */
18
    private array $dispatchers = [];
19
20 2
    public function dispatch(object $event)
21
    {
22 2
        foreach ($this->dispatchers as $dispatcher) {
23 2
            if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
24 1
                return $event;
25
            }
26 2
            $event = $dispatcher->dispatch($event);
27
        }
28
29 1
        return $event;
30
    }
31
32 2
    public function attach(EventDispatcherInterface $dispatcher): void
33
    {
34 2
        $this->dispatchers[] = $dispatcher;
35
    }
36
}
37