Completed
Push — master ( 9792a6...aaaf86 )
by recca
10:22
created

LaravelTracyServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
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 1
            ->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 1
            $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 1
    public function register()
82
    {
83 1
        $this->mergeConfigFrom(__DIR__.'/../config/tracy.php', 'tracy');
84
85 1
        $config = Arr::get($this->app['config'], 'tracy');
86
87 1
        if (Arr::get($config, 'panels.terminal') === true) {
88 1
            $this->app->register(TerminalServiceProvider::class);
89
        }
90
91 1
        $this->app->singleton(BlueScreen::class, function () {
92 1
            return Debugger::getBlueScreen();
93 1
        });
94
95 1
        $this->app->singleton(Bar::class, function ($app) use ($config) {
96 1
            return (new BarManager(Debugger::getBar(), $app['request'], $app))
97 1
                ->loadPanels(Arr::get($config, 'panels', []))
98 1
                ->getBar();
99 1
        });
100
101 1
        $this->app->singleton(DebuggerManager::class, function ($app) use ($config) {
102 1
            return (new DebuggerManager(
103 1
                DebuggerManager::init($config),
104 1
                $app[Bar::class],
105 1
                $app[BlueScreen::class],
106 1
                new Session
107 1
            ))->setUrlGenerator($app['url']);
108 1
        });
109 1
    }
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) {
0 ignored issues
show
Bug introduced by
The method routesAreCached() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
130 1
            $router->group(array_merge([
131 1
                'namespace' => $this->namespace,
132 1
            ], $config), function (Router $router) {
133
                require __DIR__.'/../routes/web.php';
134 1
            });
135
        }
136 2
    }
137
}
138