WebTinkerServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
eloc 29
c 3
b 1
f 1
dl 0
loc 55
rs 10
wmc 5

4 Methods

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

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

65
        Gate::define('viewWebTinker', function (/** @scrutinizer ignore-unused */ $user = null) {

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

Loading history...
66
            return app()->environment('local');
0 ignored issues
show
introduced by freek
The method environment() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
            return app()->/** @scrutinizer ignore-call */ environment('local');
Loading history...
67
        });
68
69
        return $this;
70
    }
71
}
72