ShortenerServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 97.22%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 5
dl 0
loc 75
ccs 35
cts 36
cp 0.9722
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 47 2
A register() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MuhamedDidovic\Shortener;
6
7
use Illuminate\Support\Facades\View;
8
use Illuminate\Support\ServiceProvider;
9
use MuhamedDidovic\Shortener\Console\ShortenerCommand;
10
use MuhamedDidovic\Shortener\Models\Link;
11
use MuhamedDidovic\Shortener\Observers\LinkObserver;
12
13
class ShortenerServiceProvider extends ServiceProvider
14
{
15
    /**
16
     * Bootstrap the application services.
17
     *
18
     * @return void
19
     */
20 42
    public function boot()
21
    {
22
        /*
23
         * Add observer for Link model
24
         */
25 42
        Link::observe(LinkObserver::class);
26
27
        /*
28
         * Optional methods to load your package assets
29
         */
30 42
        $source = realpath($raw = __DIR__.'/../config/shortener.php') ?: $raw;
31 42
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'shortener');
32 42
        $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
33 42
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
34
35 42
        $this->publishes([
36 42
            $source => config_path('shortener.php'),
37 42
        ], 'shortener::config');
38
39 42
        $this->publishes([
40 42
            __DIR__.'/../database/migrations' => database_path('migrations'),
41 42
        ], 'shortener::migrations');
42
43
        // Publishing the views.
44 42
        $this->publishes([
45 42
            __DIR__.'/../resources/views' => resource_path('views/vendor/shortener'),
46 42
        ], 'shortener::views');
47
48
        // Publishing assets.
49 42
        $this->publishes([
50 42
            __DIR__.'/../resources/views' => resource_path('views/vendor/shortener'),
51 42
            __DIR__.'/../resources/js'    => resource_path('js'),
52 42
            __DIR__.'/../resources/sass'  => resource_path('sass'),
53 42
            __DIR__.'/../public/css'      => public_path('css/'),
54 42
            __DIR__.'/../public/js'       => public_path('js/'),
55 42
        ], 'shortener::assets');
56
57
        // Registering package commands.
58 42
        $this->commands([
59 42
            ShortenerCommand::class,
60
        ]);
61
62
        // Using Closure based composers.
63 42
        View::composer('shortener::shortener', function ($view) {
64
            $view->with('routes', config('shortener.routes'));
65 42
        });
66 42
    }
67
68
    /**
69
     * Register the application services.
70
     *
71
     * @return void
72
     */
73 42
    public function register()
74
    {
75 42
        $source = realpath($raw = __DIR__.'/../config/shortener.php') ?: $raw;
76
77
        // Automatically apply the package configuration
78 42
        $this->mergeConfigFrom($source, 'shortener');
79
80
        // Register the main class to use with the facade
81 42
        $this->app->singleton('shortener', function () {
82 22
            return new Shortener();
83 42
        });
84
85 42
        $this->app->alias('shortener', Shortener::class);
86 42
    }
87
}
88