Test Failed
Pull Request — master (#952)
by Maxim
16:49 queued 07:48
created

EventsConfig   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 15
dl 0
loc 50
ccs 14
cts 14
cp 1
rs 10
c 2
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getListeners() 0 11 2
A getInterceptors() 0 3 1
A normalizeListener() 0 3 2
A getProcessors() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Events\Config;
6
7
use Spiral\Core\Container\Autowire;
8
use Spiral\Core\CoreInterceptorInterface;
9
use Spiral\Core\InjectableConfig;
10
use Spiral\Events\Processor\ProcessorInterface;
11
12
/**
13
 * @psalm-type TProcessor = ProcessorInterface|class-string<ProcessorInterface>|Autowire<ProcessorInterface>
14
 * @psalm-type TListener = class-string|EventListener
15
 * @psalm-type TInterceptor = class-string<CoreInterceptorInterface>|CoreInterceptorInterface|Autowire<CoreInterceptorInterface>
16
 * @property array{
17
 *     processors: TProcessor[],
18
 *     listeners: array<class-string, TListener[]>,
19
 *     interceptors: TInterceptor[]
20
 * } $config
21
 */
22
final class EventsConfig extends InjectableConfig
23
{
24
    public const CONFIG = 'events';
25
26
    protected array $config = [
27
        'processors' => [],
28
        'listeners' => [],
29
        'interceptors' => [],
30
    ];
31
32
    /**
33
     * Get registered listeners.
34
     *
35
     * @return array<class-string, EventListener[]>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string, EventListener[]> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string, EventListener[]>.
Loading history...
36
     */
37 5
    public function getListeners(): array
38
    {
39 5
        $listeners = [];
40 5
        foreach ($this->config['listeners'] as $event => $eventListeners) {
41 4
            $listeners[$event] = \array_map(
42 4
                self::normalizeListener(...),
43 4
                $eventListeners
44 4
            );
45
        }
46
47 5
        return $listeners;
48
    }
49
50
    /**
51
     * @return TProcessor[]
52
     */
53 293
    public function getProcessors(): array
54
    {
55 293
        return $this->config['processors'];
56
    }
57
58
    /**
59
     * @return TInterceptor[]
60
     */
61 8
    public function getInterceptors(): array
62
    {
63 8
        return $this->config['interceptors'];
64
    }
65
66
    /**
67
     * @param TListener $listener
0 ignored issues
show
Bug introduced by
The type Spiral\Events\Config\TListener 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...
68
     */
69 4
    private static function normalizeListener(string|EventListener $listener): EventListener
0 ignored issues
show
Unused Code introduced by
The method normalizeListener() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
70
    {
71 4
        return \is_string($listener) ? new EventListener($listener) : $listener;
72
    }
73
}
74