Completed
Push — master ( 53fb95...674a62 )
by recca
31:52 queued 27:07
created

LaravelTracyServiceProvider::handleRoutes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
ccs 6
cts 7
cp 0.8571
crap 2.0116
1
<?php
2
3
namespace Recca0120\LaravelTracy;
4
5
use Tracy\Bar;
6
use Tracy\Debugger;
7
use Tracy\BlueScreen;
8
use Illuminate\Support\Arr;
9
use Illuminate\Routing\Router;
10
use Illuminate\Contracts\Http\Kernel;
11
use Illuminate\Support\ServiceProvider;
12
use Illuminate\Contracts\View\Factory as View;
13
use Recca0120\LaravelTracy\Exceptions\Handler;
14
use Recca0120\Terminal\TerminalServiceProvider;
15
use Illuminate\Contracts\Debug\ExceptionHandler;
16
use Recca0120\LaravelTracy\Middleware\RenderBar;
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
        $view->getEngineResolver()
45 2
            ->resolve('blade')
46 2
            ->getCompiler()
47
            ->directive('bdump', function ($expression) {
48 2
                return "<?php \Tracy\Debugger::barDump({$expression}); ?>";
49 2
            });
50
51 2
        if ($this->app->runningInConsole() === true) {
52 1
            $this->publishes([__DIR__.'/../config/tracy.php' => config_path('tracy.php')], 'config');
53
54 1
            return;
55
        }
56
57 1
        $config = $this->app['config']['tracy'];
58 1
        $enabled = Arr::get($config, 'enabled', true) === true;
59 1
        if ($enabled === false) {
60
            return;
61
        }
62
63 1
        $showException = Arr::get($config, 'showException', true);
64 1
        if ($showException === true) {
65
            $this->app->extend(ExceptionHandler::class, function ($exceptionHandler, $app) {
66 1
                return new Handler($exceptionHandler, $app[DebuggerManager::class]);
67 1
            });
68
        }
69
70 1
        $showBar = Arr::get($config, 'showBar', true);
71 1
        if ($showBar === true) {
72 1
            $this->handleRoutes($router, Arr::get($config, 'route', []));
73 1
            $kernel->prependMiddleware(RenderBar::class);
74
        }
75 1
    }
76
77
    /**
78
     * Register the service provider.
79
     */
80
    public function register()
81
    {
82
        $this->mergeConfigFrom(__DIR__.'/../config/tracy.php', 'tracy');
83
84
        $config = Arr::get($this->app['config'], 'tracy');
85
86
        if (Arr::get($config, 'panels.terminal') === true) {
87
            $this->app->register(TerminalServiceProvider::class);
88
        }
89
90
        $this->app->singleton(BlueScreen::class, function () {
91
            return Debugger::getBlueScreen();
92
        });
93
94
        $this->app->singleton(Bar::class, function ($app) use ($config) {
95
            return (new BarManager(Debugger::getBar(), $app['request'], $app))
96
                ->loadPanels(Arr::get($config, 'panels', []))
97
                ->getBar();
98
        });
99
100
        $this->app->singleton(DebuggerManager::class, function ($app) use ($config) {
101
            return (new DebuggerManager(
102
                DebuggerManager::init($config),
103
                $app[Bar::class],
104
                $app[BlueScreen::class],
105
                new Session
106
            ))->setUrlGenerator($app['url']);
107
        });
108
    }
109
110
    /**
111
     * Get the services provided by the provider.
112
     *
113
     * @return array
114
     */
115 1
    public function provides()
116
    {
117 1
        return [ExceptionHandler::class];
118
    }
119
120
    /**
121
     * register routes.
122
     *
123
     * @param \Illuminate\Routing\Router $router
124
     * @param array $config
125
     */
126 1
    protected function handleRoutes(Router $router, $config = [])
127
    {
128 1
        if ($this->app->routesAreCached() === false) {
129 1
            $router->group(array_merge([
130 1
                'namespace' => $this->namespace,
131
            ], $config), function (Router $router) {
132
                require __DIR__.'/../routes/web.php';
133 1
            });
134
        }
135 1
    }
136
}
137