Passed
Pull Request — master (#74)
by Rustam
02:43
created

DebugServiceProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
eloc 8
c 8
b 0
f 0
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug;
6
7
use Psr\Container\ContainerInterface;
8
use Psr\EventDispatcher\EventDispatcherInterface;
9
use Psr\Log\LoggerInterface;
10
use Yiisoft\Di\Container;
11
use Yiisoft\Di\Support\ServiceProvider;
12
use Yiisoft\Yii\Debug\Collector\EventCollector;
13
use Yiisoft\Yii\Debug\Collector\LogCollector;
14
use Yiisoft\Yii\Debug\Proxy\EventDispatcherInterfaceProxy;
15
use Yiisoft\Yii\Debug\Proxy\LoggerInterfaceProxy;
16
17
final class DebugServiceProvider extends ServiceProvider
18
{
19 1
    public function register(Container $container): void
20
    {
21 1
        $logger = $container->get(LoggerInterface::class);
22 1
        $dispatcher = $container->get(EventDispatcherInterface::class);
23
24
        /**
25
         * @psalm-suppress InaccessibleMethod
26
         */
27 1
        $container->setMultiple(
28
            [
29
                // interfaces overriding
30 1
                LoggerInterface::class => static function (ContainerInterface $container) use ($logger) {
31 1
                    return new LoggerInterfaceProxy($logger, $container->get(LogCollector::class));
32 1
                },
33 1
                EventDispatcherInterface::class => static function (ContainerInterface $container) use ($dispatcher) {
34 1
                    return new EventDispatcherInterfaceProxy($dispatcher, $container->get(EventCollector::class));
35 1
                },
36
            ]
37
        );
38 1
    }
39
}
40