LaravelSmartBlogServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 96.77%

Importance

Changes 9
Bugs 0 Features 4
Metric Value
eloc 36
c 9
b 0
f 4
dl 0
loc 79
ccs 30
cts 31
cp 0.9677
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 58 4
A register() 0 8 1
1
<?php
2
3
namespace DavideCasiraghi\LaravelSmartBlog;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\ServiceProvider;
7
8
class LaravelSmartBlogServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     */
13 52
    public function boot()
14
    {
15
        /*
16
         * Optional methods to load your package assets
17
         */
18 52
        $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-smart-blog');
19 52
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-smart-blog');
20 52
        $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
21
22 52
        $this->app['router']->aliasMiddleware('admin', \DavideCasiraghi\LaravelSmartBlog\Http\Middleware\Admin::class);
23
24 52
        if ($this->app->runningInConsole()) {
25 52
            $this->publishes([
26 52
                __DIR__.'/../config/config.php' => config_path('laravel-smart-blog.php'),
27 52
            ], 'config');
28
29
            // Publishing the views.
30 52
            $this->publishes([
31 52
                __DIR__.'/../resources/views' => resource_path('views/vendor/laravel-smart-blog/'),
32 52
            ], 'views');
33
34
            // Publishing assets.
35
            /*$this->publishes([
36
                __DIR__.'/../resources/assets' => public_path('vendor/laravel-smart-blog'),
37
            ], 'assets');*/
38 52
            $this->publishes([
39 52
                __DIR__.'/../resources/assets/sass' => resource_path('sass/vendor/laravel-smart-blog/'),
40 52
            ], 'sass');
41 52
            $this->publishes([
42 52
                __DIR__.'/../resources/assets/js' => resource_path('js/vendor/laravel-smart-blog/'),
43 52
            ], 'js');
44
45
            // Publishing the translation files.
46 52
            $this->publishes([
47 52
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-smart-blog'),
48 52
            ], 'lang');
49
50
            // Registering package commands.
51
            // $this->commands([]);
52
53
            /* - Migrations -
54
               create a migration instance for each .php.stub file eg.
55
               create_continents_table.php.stub --->  2019_04_28_190434761474_create_continents_table.php
56
            */
57
            $migrations = [
58 52
                     'CreateBlogsTable' => 'create_blogs_table',
59
                     'CreateBlogTranslationsTable' => 'create_blog_translations_table',
60
                     'CreateCategoriesTable' => 'create_categories_table',
61
                     'CreateCategoryTranslationsTable' => 'create_category_translations_table',
62
                     'CreatePostsTable' => 'create_posts_table',
63
                     'CreatePostTranslationsTable' => 'create_post_translations_table',
64
                 ];
65
66 52
            foreach ($migrations as $migrationFunctionName => $migrationFileName) {
67 52
                if (! class_exists($migrationFunctionName)) {
68 1
                    $this->publishes([
69 1
                             __DIR__.'/../database/migrations/'.$migrationFileName.'.php.stub' => database_path('migrations/'.Carbon::now()->format('Y_m_d_Hmsu').'_'.$migrationFileName.'.php'),
70 52
                         ], 'migrations');
71
                }
72
            }
73
        }
74 52
    }
75
76
    /**
77
     * Register the application services.
78
     */
79 52
    public function register()
80
    {
81
        // Automatically apply the package configuration
82 52
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-smart-blog');
83
84
        // Register the main class to use with the facade
85
        $this->app->singleton('laravel-smart-blog', function () {
86
            return new LaravelSmartBlog;
87 52
        });
88 52
    }
89
}
90