Completed
Pull Request — master (#58)
by
unknown
01:30
created

LaravelTracyServiceProvider::boot()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 5.0023

Importance

Changes 0
Metric Value
cc 5
nc 6
nop 3
dl 0
loc 35
ccs 21
cts 22
cp 0.9545
crap 5.0023
rs 9.0488
c 0
b 0
f 0
1
<?php
2
3
namespace Recca0120\LaravelTracy;
4
5
use Illuminate\Contracts\Debug\ExceptionHandler;
6
use Illuminate\Contracts\Http\Kernel;
7
use Illuminate\Contracts\View\Factory as View;
8
use Illuminate\Routing\Router;
9
use Illuminate\Support\Arr;
10
use Illuminate\Support\ServiceProvider;
11
use Recca0120\LaravelTracy\Exceptions\Handler;
12
use Recca0120\LaravelTracy\Middleware\RenderBar;
13
use Recca0120\Terminal\TerminalServiceProvider;
14
use Tracy\Bar;
15
use Tracy\BlueScreen;
16
use Tracy\Debugger;
17
18
class LaravelTracyServiceProvider extends ServiceProvider
19
{
20
    /**
21
     * Indicates if loading of the provider is deferred.
22
     *
23
     * @var bool
24
     */
25
    protected $defer = false;
26
27
    /**
28
     * namespace.
29
     *
30
     * @var string
31
     */
32
    protected $namespace = 'Recca0120\LaravelTracy\Http\Controllers';
33
34
    /**
35
     * boot.
36
     *
37
     * @param DebuggerManager $debuggerManager
0 ignored issues
show
Bug introduced by
There is no parameter named $debuggerManager. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
38
     * @param \Illuminate\Contracts\Http\Kernel $kernel
39
     * @param \Illuminate\Contracts\View\Factory $view
40
     * @param \Illuminate\Routing\Router $router
41
     */
42 2
    public function boot(Kernel $kernel, View $view, Router $router)
43
    {
44 2
        $config = $this->app['config']['tracy'];
45 2
        $this->handleRoutes($router, Arr::get($config, 'route', []));
46
47 2
        if ($this->app->runningInConsole() === true) {
48 1
            $this->publishes([__DIR__.'/../config/tracy.php' => config_path('tracy.php')], 'config');
49
50 1
            return;
51
        }
52
53 1
        $view->getEngineResolver()
54 1
            ->resolve('blade')
55 1
            ->getCompiler()
56
            ->directive('bdump', function ($expression) {
57 1
                return "<?php \Tracy\Debugger::barDump({$expression}); ?>";
58 1
            });
59
60 1
        $enabled = Arr::get($config, 'enabled', true) === true;
61 1
        if ($enabled === false) {
62
            return;
63
        }
64
65 1
        $showException = Arr::get($config, 'showException', true);
66 1
        if ($showException === true) {
67
            $this->app->extend(ExceptionHandler::class, function ($exceptionHandler, $app) {
68 1
                return new Handler($exceptionHandler, $app[DebuggerManager::class]);
69 1
            });
70
        }
71
72 1
        $showBar = Arr::get($config, 'showBar', true);
73 1
        if ($showBar === true) {
74 1
            $kernel->prependMiddleware(RenderBar::class);
75
        }
76 1
    }
77
78
    /**
79
     * Register the service provider.
80
     */
81
    public function register()
82
    {
83
        $this->mergeConfigFrom(__DIR__.'/../config/tracy.php', 'tracy');
84
85
        $config = Arr::get($this->app['config'], 'tracy');
86
87
        if (Arr::get($config, 'panels.terminal') === true) {
88
            $this->app->register(TerminalServiceProvider::class);
89
        }
90
91
        $this->app->singleton(BlueScreen::class, function () {
92
            return Debugger::getBlueScreen();
93
        });
94
95
        $this->app->singleton(Bar::class, function ($app) use ($config) {
96
            return (new BarManager(Debugger::getBar(), $app['request'], $app))
97
                ->loadPanels(Arr::get($config, 'panels', []))
98
                ->getBar();
99
        });
100
101
        $this->app->singleton(DebuggerManager::class, function ($app) use ($config) {
102
            return (new DebuggerManager(
103
                DebuggerManager::init($config),
104
                $app[Bar::class],
105
                $app[BlueScreen::class],
106
                new Session
107
            ))->setUrlGenerator($app['url']);
108
        });
109
    }
110
111
    /**
112
     * Get the services provided by the provider.
113
     *
114
     * @return array
115
     */
116 1
    public function provides()
117
    {
118 1
        return [ExceptionHandler::class];
119
    }
120
121
    /**
122
     * register routes.
123
     *
124
     * @param \Illuminate\Routing\Router $router
125
     * @param array $config
126
     */
127 2
    protected function handleRoutes(Router $router, $config = [])
128
    {
129 2
        if ($this->app->routesAreCached() === false) {
130 1
            $router->group(array_merge([
131 1
                'namespace' => $this->namespace,
132
            ], $config), function (Router $router) {
133
                require __DIR__.'/../routes/web.php';
134 1
            });
135
        }
136 2
    }
137
}
138