PreviewServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 6
Bugs 2 Features 2
Metric Value
wmc 7
c 6
b 2
f 2
lcom 1
cbo 1
dl 0
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 18 3
A register() 0 4 1
A isEnabled() 0 4 3
1
<?php
2
3
namespace Gregoriohc\Preview;
4
5
use Illuminate\Support\Facades\Route;
6
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
7
8
class PreviewServiceProvider extends LaravelServiceProvider
9
{
10
    /**
11
     * Indicates if loading of the provider is deferred.
12
     *
13
     * @var bool
14
     */
15
    protected $defer = false;
16
17
    /**
18
     * Bootstrap the application events.
19
     *
20
     * @return void
21
     */
22
    public function boot()
23
    {
24
        $this->publishes([
25
            __DIR__.'/../config/preview.php' => config_path('preview.php'),
26
        ]);
27
28
        if (!$this->app->routesAreCached()) {
29
            $middleware = [];
30
            if (request()->has('_middleware')) {
31
                $middleware = array_merge(config('preview.middleware'), explode(',', request('_middleware')));
32
            }
33
34
            Route::group(['middleware' => $middleware], function () {
35
                $route = trim(config('preview.route'), '\\');
36
                Route::get($route.'/{view}', '\Gregoriohc\Preview\Controller@show')->name('_preview.show');
37
            });
38
        }
39
    }
40
41
    /**
42
     * Register the service provider.
43
     *
44
     * @return void
45
     */
46
    public function register()
47
    {
48
        $this->mergeConfigFrom(__DIR__.'/../config/preview.php', 'preview');
49
    }
50
51
    /**
52
     * Check if the package is enabled.
53
     *
54
     * @return bool
55
     */
56
    public static function isEnabled()
57
    {
58
        return (config('app.debug') && 'local' === config('app.env')) || config('preview.force_enable');
59
    }
60
}
61