Completed
Pull Request — master (#39)
by
unknown
02:05
created

LaravelTracyServiceProvider::handleRoutes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

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