CompositeProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 5
dl 0
loc 20
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A attach() 0 3 1
A getListenersForEvent() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\EventDispatcher\Provider;
6
7
use Psr\EventDispatcher\ListenerProviderInterface;
8
9
/**
10
 * CompositeProvider is a listener provider that allows combining multiple listener providers.
11
 */
12
final class CompositeProvider implements ListenerProviderInterface
13
{
14
    /**
15
     * @var ListenerProviderInterface[]
16
     */
17
    private array $providers = [];
18
19 1
    public function getListenersForEvent(object $event): iterable
20
    {
21 1
        foreach ($this->providers as $provider) {
22 1
            yield from $provider->getListenersForEvent($event);
23
        }
24
    }
25
26
    /**
27
     * Adds provider as a source for event listeners.
28
     */
29 1
    public function attach(ListenerProviderInterface $provider): void
30
    {
31 1
        $this->providers[] = $provider;
32
    }
33
}
34