EventServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 3
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace ByTIC\EventDispatcher;
4
5
use ByTIC\EventDispatcher\Discovery\RegisterDiscoveredEvents;
6
use ByTIC\EventDispatcher\Dispatcher\EventDispatcher;
7
use ByTIC\EventDispatcher\Dispatcher\EventDispatcherInterface;
8
use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider;
9
use Nip\Container\ServiceProviders\Providers\BootableServiceProviderInterface;
10
use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
11
use Symfony\Component\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface;
12
13
/**
14
 * Class EventServiceProvider
15
 * @package ByTIC\EventDispatcher
16
 */
17
class EventServiceProvider extends AbstractSignatureServiceProvider implements BootableServiceProviderInterface
18
{
19 3
    public const DIPATCHER_NAME = 'events';
20
21 3
    /**
22 3
     * @inheritdoc
23 3
     */
24
    public function register()
25 3
    {
26
        $this->registerDispatcher();
27
    }
28
29 3
    public function boot()
30 3
    {
31
        $dispatcher = $this->getContainer()->get(static::DIPATCHER_NAME);
32 3
        $provider = new RegisterDiscoveredEvents($dispatcher);
33
        $provider->register();
34 3
    }
35 3
36
    protected function registerDispatcher()
37
    {
38
        $this->getContainer()->share('events', function () {
39 2
            return new EventDispatcher();
40 3
        });
41 3
    }
42
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function provides(): array
48
    {
49
        return [
50
            self::DIPATCHER_NAME,
51
            EventDispatcherInterface::class,
52
            PsrEventDispatcherInterface::class,
53
            SymfonyEventDispatcherInterface::class
54
        ];
55
    }
56
}
57