Passed
Push — master ( 31d344...83ac3f )
by Alexander
01:22
created

CompositeProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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