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

CompositeProvider::attach()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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