Test Setup Failed
Push — master ( c4d24d...9082b2 )
by Gabriel
13:27
created

DebugServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 45
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 4 1
A register() 0 5 1
A registerDebug() 0 6 1
A registerErrorHandler() 0 12 2
A boot() 0 4 1
1
<?php
2
3
namespace Nip\Debug;
4
5
use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider;
6
use Nip\Container\ServiceProviders\Providers\BootableServiceProviderInterface;
7
use Psr\Log\LoggerInterface;
8
use Symfony\Component\ErrorHandler\BufferingLogger;
9
use Nip\Debug\ErrorHandler;
10
11
/**
12
 * Class LoggerServiceProvider
13
 * @package Nip\Logger
14
 */
15
class DebugServiceProvider extends AbstractSignatureServiceProvider implements BootableServiceProviderInterface
16
{
17
18
    /**
19
     * @inheritdoc
20
     */
21
    public function provides()
22
    {
23
        return ['debug', 'error-handler', ErrorHandler::class];
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function register()
30
    {
31
        $this->registerDebug();
32
        $this->registerErrorHandler();
33
    }
34
35
    public function registerDebug()
36
    {
37
        $this->getContainer()->share('debug', function () {
38
            return new Debug();
39
        });
40
    }
41
42
    public function registerErrorHandler()
43
    {
44
        $this->getContainer()->share('error-handler', function () {
45
            $logger = $this->getContainer()->has(LoggerInterface::class)
46
                ? $this->getContainer()->get(LoggerInterface::class)
47
                : new BufferingLogger();
48
49
            return new ErrorHandler($logger);
50
        });
51
52
        $this->getContainer()->alias('error-handler', ErrorHandler::class);
53
    }
54
55
    public function boot()
56
    {
57
        ErrorHandler::register($this->getContainer()->get(ErrorHandler::class), true);
58
    }
59
}
60