ApplicationListenerProvider::getName()   A
last analyzed

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 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 *  This file is part of the Micro framework package.
5
 *
6
 *  (c) Stanislau Komar <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace Micro\Plugin\EventEmitter\Business\Provider;
13
14
use Micro\Component\DependencyInjection\Autowire\AutowireHelperInterface;
15
use Micro\Component\EventEmitter\EventInterface;
16
use Micro\Component\EventEmitter\EventListenerInterface;
17
use Micro\Component\EventEmitter\ListenerProviderInterface;
18
19
class ApplicationListenerProvider implements ListenerProviderInterface
20
{
21
    /**
22
     * @template T of EventListenerInterface
23
     *
24
     * @param iterable<class-string<T>> $eventListenersClasses
25
     */
26 6
    public function __construct(
27
        private readonly AutowireHelperInterface $autowireHelper,
28
        private readonly iterable $eventListenersClasses,
29
    ) {
30 6
    }
31
32
    /**
33
     * {@inheritDoc}
34
     */
35 3
    public function getListenersForEvent(EventInterface $event): iterable
36
    {
37 3
        foreach ($this->getEventListeners() as $listenerClass) {
38 2
            if (!$listenerClass::supports($event)) {
39 1
                continue;
40
            }
41
42 1
            $callback = $this->autowireHelper->autowire($listenerClass);
43
44 1
            yield $callback();
45
        }
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 1
    public function __toString(): string
52
    {
53 1
        return $this->getName();
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59 2
    public function getName(): string
60
    {
61 2
        return 'events.listener_provider.default';
62
    }
63
64
    /**
65
     * {@inheritDoc}
66
     */
67 4
    public function getEventListeners(): iterable
68
    {
69 4
        return $this->eventListenersClasses;
70
    }
71
}
72