Completed
Push — master ( d49b73...f27323 )
by
unknown
04:02
created

ExceptionServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 7 2
A registerWhoops() 0 11 1
A registerPrettyWhoopsHandler() 0 9 1
1
<?php
2
3
namespace Magister\Services\Exception;
4
5
use Magister\Services\Support\ServiceProvider;
6
use Whoops\Handler\JsonResponseHandler;
7
use Whoops\Handler\PrettyPageHandler;
8
use Whoops\Run;
9
10
/**
11
 * Class ExceptionServiceProvider.
12
 */
13
class ExceptionServiceProvider extends ServiceProvider
14
{
15
    /**
16
     * Register bindings in the container.
17
     *
18
     * @return void
19
     */
20
    public function register()
21
    {
22
        if (class_exists('Whoops\Run')) {
23
            $this->registerPrettyWhoopsHandler();
24
            $this->registerWhoops();
25
        }
26
    }
27
28
    /**
29
     * Register the Whoops error display service.
30
     *
31
     * @return void
32
     */
33
    protected function registerWhoops()
34
    {
35
        // We will instruct Whoops to not exit after it displays the exception as it
36
        // will otherwise run out before we can do anything else. We just want to
37
        // let the framework go ahead and finish a request on this end instead.
38
        with($whoops = new Run)->allowQuit(false);
39
40
        $whoops->pushHandler($this->app['whoops.handler']);
41
42
        $whoops->register();
43
    }
44
45
    /**
46
     * Register the "pretty" Whoops handler.
47
     *
48
     * @return void
49
     */
50
    protected function registerPrettyWhoopsHandler()
51
    {
52
        $this->app['whoops.handler'] = $this->app->share(function()
53
        {
54
            with($handler = new PrettyPageHandler)->setEditor('sublime');
55
56
            return $handler;
57
        });
58
    }
59
}
60