WebTinkerServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 24 2
A register() 0 6 1
A registerRoutes() 0 9 1
A registerWebTinkerGate() 0 8 1
1
<?php
2
3
namespace Spatie\WebTinker;
4
5
use Illuminate\Support\Facades\Gate;
6
use Illuminate\Support\Facades\Route;
7
use Illuminate\Support\ServiceProvider;
8
use Spatie\WebTinker\Console\InstallCommand;
9
use Spatie\WebTinker\Http\Middleware\Authorize;
10
use Spatie\WebTinker\OutputModifiers\OutputModifier;
11
use Spatie\WebTinker\Http\Controllers\WebTinkerController;
12
13
class WebTinkerServiceProvider extends ServiceProvider
14
{
15
    public function boot()
16
    {
17
        if ($this->app->runningInConsole()) {
18
            $this->publishes([
19
                __DIR__.'/../config/web-tinker.php' => config_path('web-tinker.php'),
20
            ], 'config');
21
22
            $this->publishes([
23
                __DIR__.'/../resources/views' => base_path('resources/views/vendor/web-tinker'),
24
            ], 'views');
25
26
            $this->publishes([
27
                __DIR__.'/../public' => public_path('vendor/web-tinker'),
28
            ], 'web-tinker-assets');
29
        }
30
31
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'web-tinker');
32
33
        $this->app->bind(OutputModifier::class, config('web-tinker.output_modifier'));
34
35
        $this
36
            ->registerRoutes()
37
            ->registerWebTinkerGate();
38
    }
39
40
    public function register()
41
    {
42
        $this->mergeConfigFrom(__DIR__.'/../config/web-tinker.php', 'web-tinker');
43
44
        $this->commands(InstallCommand::class);
45
    }
46
47
    protected function registerRoutes()
48
    {
49
        Route::prefix(config('web-tinker.path'))->middleware(Authorize::class)->group(function () {
50
            Route::get('/', [WebTinkerController::class, 'index']);
51
            Route::post('/', [WebTinkerController::class, 'execute']);
52
        });
53
54
        return $this;
55
    }
56
57
    protected function registerWebTinkerGate()
58
    {
59
        Gate::define('viewWebTinker', function ($user = null) {
0 ignored issues
show
Unused Code introduced by freek
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
            return app()->environment('local');
61
        });
62
63
        return $this;
64
    }
65
}
66