AttributeListenerProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getListenersForEvent() 0 10 3
1
<?php
2
3
/**
4
 * This file is part of Event
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\Event\Infrastructure;
13
14
use Psr\Container\ContainerExceptionInterface;
15
use Psr\Container\NotFoundExceptionInterface;
16
use Psr\EventDispatcher\ListenerProviderInterface;
17
use Slick\Event\Application\DispatcherTools;
18
19
/**
20
 * AttributeListenerProvider
21
 *
22
 * @package Slick\Event\Infrastructure
23
 */
24
final class AttributeListenerProvider implements ListenerProviderInterface
25
{
26
    use DispatcherTools;
0 ignored issues
show
Bug introduced by
The trait Slick\Event\Application\DispatcherTools requires the property $priority which is not provided by Slick\Event\Infrastructu...tributeListenerProvider.
Loading history...
27
28
    public function __construct(private readonly AttributeListenerResolver $resolver)
0 ignored issues
show
Bug introduced by
The type Slick\Event\Infrastructu...tributeListenerResolver was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
    {
30
    }
31
32
    /**
33
     * @inheritDoc
34
     *
35
     * @throws NotFoundExceptionInterface
36
     * @throws ContainerExceptionInterface
37
     */
38
    public function getListenersForEvent(object $event): iterable
39
    {
40
        $listeners = [];
41
        foreach ($this->resolver->resolve() as $binding) {
42
            if ($this->match($binding['event'], $event)) {
43
                $listeners[] = (object) ['listener' => $binding['listener'], 'priority' => $binding['priority']];
44
            }
45
        }
46
47
        return array_map(fn ($data) => $data->listener, $this->orderedListeners($listeners));
48
    }
49
}
50